[tor-commits] [tor/master] When using open() to make sure we created a dir, close the fd afterwards
nickm at torproject.org
nickm at torproject.org
Mon Mar 14 17:04:08 UTC 2016
commit 36ad65a7d1709deeb4bc1ae3e994a30c3e7bf789
Author: Nick Mathewson <nickm at torproject.org>
Date: Mon Mar 14 13:02:50 2016 -0400
When using open() to make sure we created a dir, close the fd afterwards
Found by coverity. Not in any released Tor. Fixes CID 1355640.
Also, don't check for fd correctness with assert(fd). You need to
assert (fd >= 0).
---
src/common/util.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/common/util.c b/src/common/util.c
index b435511..e8be91f 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2114,7 +2114,10 @@ check_private_dir(const char *dirname, cpd_check_t check,
* permissions on the directory will be checked again below.*/
fd = open(sandbox_intern_string(dirname), O_NOFOLLOW);
- if ( fd == -1 ) return -1;
+ if (fd == -1)
+ return -1;
+ else
+ close(fd);
} else if (!(check & CPD_CHECK)) {
log_warn(LD_FS, "Directory %s does not exist.", dirname);
@@ -2126,7 +2129,7 @@ check_private_dir(const char *dirname, cpd_check_t check,
return 0;
}
- tor_assert(fd);
+ tor_assert(fd >= 0);
//f = tor_strdup(dirname);
//clean_name_for_stat(f);
More information about the tor-commits
mailing list