Fix oversights from 4170ae4e

4170ae4ea6 was intended to tackle TOCTOU
race conditions reported by CodeQL, but as an oversight, a file
descriptor was not closed and some comments were not updated.
Interestingly, CodeQL did not complain about the file descriptor leak,
so there is room for improvement in how we configure it to try to detect
this issue so that we get early warning about this.

In addition, an optimization opportunity was missed by mistake in
lib/libshare/os/linux/smb.c, which prevented us from truly closing the
TOCTOU race. This was also caught by Coverity.

Reported-by: Coverity (CID 1524424)
Reported-by: Coverity (CID 1526804)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14109
This commit is contained in:
Richard Yao
2022-10-31 13:01:04 -04:00
committed by GitHub
parent b37d495e04
commit dcce0dc5f0
2 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ smb_retrieve_shares(void)
goto out;
}
if (stat(file_path, &eStat) == -1) {
if (fstat(fd, &eStat) == -1) {
close(fd);
rc = SA_SYSTEM_ERR;
goto out;