syscalls: truncate: fix call to filesystem_put_node()
filesystem_put_node() should be called only if the previous call to
filesystem_get_node() was successful, otherwise the filesystem
reference count is wrongly decremented (and the filesystem lock is
wrongly released if held by another thread).
@@ -1238,7 +1238,8 @@ sysreturn truncate(const char *path, long length)
sysreturn rv;
if (fss != FS_STATUS_OK) {
rv = sysreturn_from_fs_status(fss);
- } else if (!(file_meta_perms(current->p, t) & ACCESS_PERM_WRITE)) {
+ } else {
+ if (!(file_meta_perms(current->p, t) & ACCESS_PERM_WRITE)) {
rv = -EACCES;
} else if (is_dir(t)) {
rv = -EISDIR;
@@ -1249,6 +1250,7 @@ sysreturn truncate(const char *path, long length)
rv = 0;
}
filesystem_put_node(fs, t);
+ }
if (rv == 0) {
rv = truncate_internal(fs, fsf, 0, length);
fsfile_release(fsf);
