From: Ronny Chevalier Date: Sun, 9 Nov 2014 14:42:23 +0000 (+0100) Subject: udev: silence TOCTOU warning when creating a directory X-Git-Tag: v218~430 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9732bae8f29be644e7b4b1cc4f738ef85477c72;p=platform%2Fupstream%2Fsystemd.git udev: silence TOCTOU warning when creating a directory CID#979416. There is no real race here to fix, but lets make coverity happy and rework the code. Note that we still fail if the directory is removed _after_ we ran mkdir(), so the same race is still there. Coverity is complaining, though. Rewrite the code to make it happy. (David: rewrote the commit-message to note that this is not a race. If I'm wrong, blame me, not Ronny!) --- diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index dc849bd..90df360 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -86,12 +86,12 @@ static void usage(void) */ static int prepare(char *dir, char *filename) { - struct stat statbuf; char buf[512]; - int fd; + int r, fd; - if (stat(dir, &statbuf) < 0) - mkdir(dir, 0700); + r = mkdir(dir, 0700); + if (r < 0 && errno != EEXIST) + return -errno; snprintf(buf, sizeof(buf), "%s/%s", dir, filename);