[systemd-devel] [PATCH] udev: fix TOCTOU when creating a directory
Ronny Chevalier
chevalier.ronny at gmail.com
Sun Nov 9 06:42:23 PST 2014
CID#979416
---
src/udev/collect/collect.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c
index dc849bd..6cb10fe 100644
--- a/src/udev/collect/collect.c
+++ b/src/udev/collect/collect.c
@@ -86,12 +86,13 @@ static void usage(void)
*/
static int prepare(char *dir, char *filename)
{
- struct stat statbuf;
char buf[512];
int fd;
+ int r;
- 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);
--
2.1.3
More information about the systemd-devel
mailing list