diff options
author | Ronny Chevalier <chevalier.ronny@gmail.com> | 2014-11-09 15:42:23 +0100 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-11-17 07:38:24 -0500 |
commit | 9f5d1bc3cdf67815d0721dc9d5e9f1049e4cffd5 (patch) | |
tree | 10a8ca99f0be8713b52065f83028bdcd49c46169 | |
parent | 6740579367ddd2ce0b315863cdb92d34d1d693c7 (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!)
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r-- | src/collect/collect.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/collect/collect.c b/src/collect/collect.c index 7bc6571146..2d1baa1ddc 100644 --- a/src/collect/collect.c +++ b/src/collect/collect.c @@ -90,12 +90,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); |