diff options
author | Ronny Chevalier <chevalier.ronny@gmail.com> | 2014-11-09 15:42:23 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2014-11-16 19:38:08 +0100 |
commit | c9732bae8f29be644e7b4b1cc4f738ef85477c72 (patch) | |
tree | 5e2efdff4f2af5143fc284dd923eb5a63ba21282 /src/udev | |
parent | 8e24a4f8b6f53883ea515ae8f27fb6b1795973b4 (diff) |
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!)
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/collect/collect.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index dc849bd0f0..90df360eb2 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); |