Platonides has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/70110


Change subject: Make dir a normal fd.
......................................................................

Make dir a normal fd.

fdopendir() takes ownership of the passed fd and thus dir was being closed 
twice.

Change-Id: I183a1b7031d7a20bb280ce17ac94a2a0ea9a8228
---
M src/take.cc
1 file changed, 14 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs 
refs/changes/10/70110/1

diff --git a/src/take.cc b/src/take.cc
index c496002..94555c7 100755
--- a/src/take.cc
+++ b/src/take.cc
@@ -129,7 +129,7 @@
                else
                        strcpy(dirname, ".");
 
-               FD dir  = open(dirname, O_RDONLY|O_NOFOLLOW);
+               int dir  = open(dirname, O_RDONLY|O_NOFOLLOW);
 
                if(dir < 0) {
                        if(errno == ELOOP)
@@ -138,17 +138,26 @@
                }
 
                struct stat     sdir;
-               if(fstat(dir, &sdir))
+               if(fstat(dir, &sdir)) {
+                       close(dir);
                        return error(dirname);
+               }
 
-               if(!S_ISDIR(sdir.st_mode))
+               if(!S_ISDIR(sdir.st_mode)) {
+                       close(dir);
                        return refuse(dirname, "containing directory doesn't 
appear to be... a directory?");
-               if(sdir.st_uid != getuid())
+               }
+
+               if(sdir.st_uid != getuid()) {
+                       close(dir);
                        return refuse(path, "you must own the containing 
directory");
+               }
 
                // Here, we are being extremely paranoid, and check that the 
file is actually in the directory.
-               if(sdir.st_dev != sfile.st_dev)
+               if(sdir.st_dev != sfile.st_dev) {
+                       close(dir);
                        return refuse(path, "the file must be on the same 
filesystem as its directory");
+               }
 
                bool found = false;
                if(DIR* df = fdopendir(dir)) {

-- 
To view, visit https://gerrit.wikimedia.org/r/70110
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I183a1b7031d7a20bb280ce17ac94a2a0ea9a8228
Gerrit-PatchSet: 1
Gerrit-Project: labs/toollabs
Gerrit-Branch: master
Gerrit-Owner: Platonides <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to