Fix a race between checking for and opening a directory to be scanned
This commit is contained in:
parent
61c205a8ad
commit
b5980682f1
@ -0,0 +1,48 @@
|
||||
From 9f6a3c484ee780b0330a24941419c0a99a10ecf8 Mon Sep 17 00:00:00 2001
|
||||
From: "Dmitry V. Levin" <ldv@altlinux.org>
|
||||
Date: Thu, 18 May 2017 12:28:10 +0300
|
||||
Subject: [PATCH] quotacheck: change to the directory before opening it, not
|
||||
after
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
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>
|
||||
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
||||
---
|
||||
quotacheck.c | 11 ++++++++---
|
||||
1 file 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) {
|
||||
--
|
||||
2.9.4
|
||||
|
||||
@ -63,6 +63,9 @@ Patch10: quota-4.03-Print-explicitely-disabled-options-properly.patch
|
||||
# Do not install quota_nld.8 when netlink support is disabled,
|
||||
# in upstream after 4.03
|
||||
Patch11: quota-4.03-Do-not-install-quota_nld.8-when-quota_nld-is-not-ins.patch
|
||||
# Fix a race between checking for and opening a directory to be scanned,
|
||||
# in upstream after 4.03
|
||||
Patch12: quota-4.03-quotacheck-change-to-the-directory-before-opening-it.patch
|
||||
BuildRequires: autoconf
|
||||
BuildRequires: automake
|
||||
BuildRequires: bash
|
||||
@ -182,6 +185,7 @@ Linux/UNIX environment.
|
||||
%patch9 -p1
|
||||
%patch10 -p1
|
||||
%patch11 -p1
|
||||
%patch12 -p1
|
||||
# Unpack forgotten LDAP scripts
|
||||
tar -xzkf %{SOURCE5}
|
||||
# Regenerate build scripts, also because of Respect-enviroment-CFLAGS.patch
|
||||
@ -299,6 +303,7 @@ make check
|
||||
%changelog
|
||||
* Tue Jul 04 2017 Petr Pisar <ppisar@redhat.com> - 1:4.03-9
|
||||
- Fix disabling features at build time
|
||||
- Fix a race between checking for and opening a directory to be scanned
|
||||
|
||||
* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1:4.03-8
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild
|
||||
|
||||
Loading…
Reference in New Issue
Block a user