diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2017-05-18 12:28:10 +0300 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2017-05-18 12:27:14 +0200 |
commit | 9f6a3c484ee780b0330a24941419c0a99a10ecf8 (patch) | |
tree | 68507f4fd7bd664fd8f03fe3ead5ec40e2aba7f1 /quotacheck.c | |
parent | 579425d669eb4df2ae26ceb70dfb9380c38fb521 (diff) | |
download | linuxquota-9f6a3c484ee780b0330a24941419c0a99a10ecf8.tar.gz |
quotacheck: change to the directory before opening it, not after
This avoids the race between opening the directory being scanned
and changing into that directory for processing its contants.
This is not the only race of that kind, but chdir return code
has to be checked anyway and the fix costs nothing, so let it be fixed.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'quotacheck.c')
-rw-r--r-- | quotacheck.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/quotacheck.c b/quotacheck.c index a6fe432..1675de8 100644 --- a/quotacheck.c +++ b/quotacheck.c @@ -508,10 +508,15 @@ static int scan_dir(const char *pathname) add_to_quota(GRPQUOTA, st.st_ino, st.st_uid, st.st_gid, st.st_mode, st.st_nlink, qspace, 0); - if ((dp = opendir(pathname)) == (DIR *) NULL) - die(2, _("\nCan open directory %s: %s\n"), pathname, strerror(errno)); + if (chdir(pathname) == -1) { + errstr(_("Cannot chdir to %s: %s\n"), pathname, strerror(errno)); + goto out; + } + + if ((dp = opendir(".")) == (DIR *) NULL) + die(2, _("\nCannot open directory %s: %s\n"), + pathname, strerror(errno)); - chdir(pathname); if (flags & FL_VERYVERBOSE) blit(pathname); while ((de = readdir(dp)) != (struct dirent *)NULL) { |