Skip to content

Commit e842115

Browse files
committed
chimera: prevent attempts to remove '.' and '..'
we have in place checks for NFS, but not for the other protocols. Acked-by: Paul MIllar Target: master, 2.11 .. 2.6 Require-book: no Require-notes: no (cherry picked from commit 8685d9a) Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de> (cherry picked from commit 2cdcfc4) Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
1 parent 6da06c1 commit e842115

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

modules/chimera/src/main/java/org/dcache/chimera/FsSqlDriver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ DirectoryStreamB<HimeraDirectoryEntry> newDirectoryStream(Connection dbConnectio
258258

259259
void remove(Connection dbConnection, FsInode parent, String name) throws ChimeraFsException, SQLException {
260260

261+
if (name.equals("..") || name.equals(".")) {
262+
throw new InvalidNameChimeraException("bad name: '" + name + "'");
263+
}
264+
261265
FsInode inode = inodeOf(dbConnection, parent, name);
262266

263267
if (inode.isDirectory()) {

modules/chimera/src/test/java/org/dcache/chimera/BasicTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,4 +962,25 @@ public void testGetParentOnRoot() throws Exception {
962962
String id = _rootInode.toString();
963963
_rootInode.inodeOf(".(parent)(" + id + ")");
964964
}
965+
966+
@Test(expected = InvalidNameChimeraException.class)
967+
public void testDeleteDot() throws Exception {
968+
969+
FsInode base = _rootInode.mkdir("dir1");
970+
base.remove(".");
971+
}
972+
973+
@Test(expected = InvalidNameChimeraException.class)
974+
public void testDeleteDotAtEnd() throws Exception {
975+
976+
FsInode base = _rootInode.mkdir("dir1");
977+
_fs.remove("/dir1/.");
978+
}
979+
980+
@Test(expected = InvalidNameChimeraException.class)
981+
public void testDeleteDotDot() throws Exception {
982+
983+
FsInode base = _rootInode.mkdir("dir1");
984+
base.remove("..");
985+
}
965986
}

0 commit comments

Comments
 (0)