mirror of
https://git.zap.org.au/git/trader.git
synced 2024-12-04 14:46:45 -05:00
Eliminate a second TOCTOU bug in xmkdir() itself
The theoretical odds of hitting this time-of-check / time-of-use bug are extremely remote. But we do want to keep Coverity Scan happy, don't we?
This commit is contained in:
parent
89fdb5a65e
commit
e3d5d04774
24
src/utils.c
24
src/utils.c
@ -1223,19 +1223,21 @@ int xmkdir (const char *pathname, mode_t mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check that pathname already exists and is a directory
|
||||
if (stat(pathname, &statbuf) == 0) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
return 0;
|
||||
} else {
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Try creating the directory
|
||||
ret = mkdir(pathname, mode);
|
||||
if (ret == 0 || (errno != ENOENT && errno != ENOTDIR)) {
|
||||
if (ret != 0 && errno == EEXIST) {
|
||||
// Pathname exists: is it a directory?
|
||||
if (stat(pathname, &statbuf) == 0) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
return 0;
|
||||
} else {
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (ret == 0 || (errno != ENOENT && errno != ENOTDIR)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user