resolved: fix TOCTOU in hook discovery
Coverity complains that the directory is not pinned by FD
so it might changed between the stat and the open
CID#1643236
Follow-up for 8209f4adcd
This commit is contained in:
@@ -391,19 +391,6 @@ static int manager_hook_discover(Manager *m) {
|
||||
|
||||
usec_t seen_usec = now(CLOCK_MONOTONIC);
|
||||
|
||||
struct stat st;
|
||||
if (stat(dp, &st) < 0) {
|
||||
if (errno == ENOENT)
|
||||
r = 0;
|
||||
else
|
||||
r = log_warning_errno(errno, "Failed to stat %s/: %m", dp);
|
||||
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (stat_inode_unmodified(&st, &m->hook_stat))
|
||||
return 0;
|
||||
|
||||
d = opendir(dp);
|
||||
if (!d) {
|
||||
if (errno == ENOENT)
|
||||
@@ -414,6 +401,15 @@ static int manager_hook_discover(Manager *m) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
if (fstat(dirfd(d), &st) < 0) {
|
||||
r = log_warning_errno(errno, "Failed to fstat %s/: %m", dp);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (stat_inode_unmodified(&st, &m->hook_stat))
|
||||
return 0;
|
||||
|
||||
for (;;) {
|
||||
errno = 0;
|
||||
struct dirent *de = readdir_no_dot(d);
|
||||
|
||||
Reference in New Issue
Block a user