]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
When using open() to make sure we created a dir, close the fd afterwards
authorNick Mathewson <nickm@torproject.org>
Mon, 14 Mar 2016 17:02:50 +0000 (13:02 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 14 Mar 2016 17:03:44 +0000 (13:03 -0400)
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

index b4355115d16d34876058735d8b4a773b61c28912..e8be91f459be3c081fc24428a73be03dda0a5728 100644 (file)
@@ -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);