Skip to content

Commit 8a0ce48

Browse files
committed
basic-server: don't allow 'set size' on directory
Acked-by: Marina Sahakyan Target: master
1 parent e0ad5eb commit 8a0ce48

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

basic-server/src/main/java/org/dcache/nfs4j/server/LocalFileSystem.java

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.cliffc.high_scale_lib.NonBlockingHashMapLong;
99
import org.dcache.nfs.FsExport;
1010
import org.dcache.nfs.status.ExistException;
11+
import org.dcache.nfs.status.InvalException;
12+
import org.dcache.nfs.status.IsDirException;
1113
import org.dcache.nfs.status.NoEntException;
1214
import org.dcache.nfs.status.NotEmptyException;
1315
import org.dcache.nfs.status.NotSuppException;
@@ -534,6 +536,17 @@ public void setattr(Inode inode, Stat stat) throws IOException {
534536
}
535537
}
536538
if (stat.isDefined(Stat.StatAttribute.SIZE)) {
539+
540+
var currentAttributes = attributeView.readAttributes();
541+
542+
if (currentAttributes.isDirectory()) {
543+
throw new IsDirException("set size on directory");
544+
}
545+
546+
if (!Files.isRegularFile(path)) {
547+
throw new InvalException("set size on non file object");
548+
}
549+
537550
try (RandomAccessFile raf = new RandomAccessFile(path.toFile(), "rw")) {
538551
raf.setLength(stat.getSize());
539552
}

0 commit comments

Comments
 (0)