From: Mathieu Desnoyers Date: Tue, 18 Jun 2013 20:00:37 +0000 (-0400) Subject: Fix: remove use of stat() X-Git-Tag: v2.2.0-rc3~11 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0c7bcad5eaa11b368460759fc87f949e8c56b98f;p=lttng-tools.git Fix: remove use of stat() 1019896 Time of check time of use In utils_mkdir_recursive: A check occurs on a file's attributes before the file is used in a privileged operation, but things may have changed (CWE-367) mkdir() is already doing the EEXIST check. Signed-off-by: Mathieu Desnoyers --- diff --git a/src/common/utils.c b/src/common/utils.c index 38f78a7e8..3e659a1c8 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -22,8 +22,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -248,7 +248,6 @@ LTTNG_HIDDEN int utils_mkdir_recursive(const char *path, mode_t mode) { char *p, tmp[PATH_MAX]; - struct stat statbuf; size_t len; int ret; @@ -276,15 +275,12 @@ int utils_mkdir_recursive(const char *path, mode_t mode) ret = -1; goto error; } - ret = stat(tmp, &statbuf); + ret = mkdir(tmp, mode); if (ret < 0) { - ret = mkdir(tmp, mode); - if (ret < 0) { - if (errno != EEXIST) { - PERROR("mkdir recursive"); - ret = -errno; - goto error; - } + if (errno != EEXIST) { + PERROR("mkdir recursive"); + ret = -errno; + goto error; } } *p = '/';