createAt should return all errors from FindInode except ENOENT.
Previously, createAt was eating all errors from FindInode except for EACCES and proceeding with the creation. This is incorrect, as FindInode can return many other errors (like ENAMETOOLONG) that should stop creation. This CL changes createAt to return all errors encountered except for ENOENT, which we can ignore because we are about to create the thing. PiperOrigin-RevId: 245773222 Change-Id: I1b317021de70f0550fb865506f6d8147d4aebc56
This commit is contained in:
parent
66bca6fc22
commit
2df64cd6d2
|
@ -347,10 +347,9 @@ func createAt(t *kernel.Task, dirFD kdefs.FD, addr usermem.Addr, flags uint, mod
|
||||||
return syserror.ConvertIntr(err, kernel.ERESTARTSYS)
|
return syserror.ConvertIntr(err, kernel.ERESTARTSYS)
|
||||||
}
|
}
|
||||||
defer newFile.DecRef()
|
defer newFile.DecRef()
|
||||||
case syserror.EACCES:
|
case syserror.ENOENT:
|
||||||
// Permission denied while walking to the file.
|
// File does not exist. Proceed with creation.
|
||||||
return err
|
|
||||||
default:
|
|
||||||
// Do we have write permissions on the parent?
|
// Do we have write permissions on the parent?
|
||||||
if err := d.Inode.CheckPermission(t, fs.PermMask{Write: true, Execute: true}); err != nil {
|
if err := d.Inode.CheckPermission(t, fs.PermMask{Write: true, Execute: true}); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -365,6 +364,8 @@ func createAt(t *kernel.Task, dirFD kdefs.FD, addr usermem.Addr, flags uint, mod
|
||||||
}
|
}
|
||||||
defer newFile.DecRef()
|
defer newFile.DecRef()
|
||||||
targetDirent = newFile.Dirent
|
targetDirent = newFile.Dirent
|
||||||
|
default:
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success.
|
// Success.
|
||||||
|
|
|
@ -51,6 +51,17 @@ TEST(CreatTest, CreatTruncatesExistingFile) {
|
||||||
EXPECT_EQ("", new_contents);
|
EXPECT_EQ("", new_contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(CreatTest, CreatWithNameTooLong) {
|
||||||
|
// Start with a unique name, and pad it to NAME_MAX + 1;
|
||||||
|
std::string name = NewTempRelPath();
|
||||||
|
int padding = (NAME_MAX + 1) - name.size();
|
||||||
|
name.append(padding, 'x');
|
||||||
|
const std::string& path = JoinPath(GetAbsoluteTestTmpdir(), name);
|
||||||
|
|
||||||
|
// Creation should return ENAMETOOLONG.
|
||||||
|
ASSERT_THAT(creat(path.c_str(), kMode), SyscallFailsWithErrno(ENAMETOOLONG));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
Loading…
Reference in New Issue