Fix file descriptor leaks in error code paths

This commit is contained in:
Petr Písař 2018-08-23 11:55:31 +02:00
parent 599891fece
commit bfc729c3dc
4 changed files with 101 additions and 1 deletions

View File

@ -0,0 +1,29 @@
From 78403029375dbfe809b5b1034301dc687a94397f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 23 Aug 2018 11:09:10 +0200
Subject: [PATCH 1/3] convertquota: Fix a file descriptor leak in
convert_endian()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
convertquota.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/convertquota.c b/convertquota.c
index d913e05..6c8a553 100644
--- a/convertquota.c
+++ b/convertquota.c
@@ -363,6 +363,7 @@ static int convert_endian(int type, struct mount_entry *mnt)
}
ret = endian_scan_structures(ofd, type);
end_io(qn);
+ close(ofd);
if (ret < 0)
return ret;
--
2.14.4

View File

@ -0,0 +1,28 @@
From 0f255ef2570478a855361937445a57a168c8629d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 23 Aug 2018 11:23:43 +0200
Subject: [PATCH 2/3] quotackeck: Fix a directory descriptor leak in scan_dir()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
quotacheck.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/quotacheck.c b/quotacheck.c
index fd01dfc..2cdf475 100644
--- a/quotacheck.c
+++ b/quotacheck.c
@@ -538,6 +538,7 @@ static int scan_dir(const char *pathname)
if ((lstat(de->d_name, &st)) == -1) {
errstr(_("lstat: Cannot stat `%s/%s': %s\nGuess you'd better run fsck first !\nexiting...\n"),
pathname, de->d_name, strerror(errno));
+ closedir(dp);
goto out;
}
--
2.14.4

View File

@ -0,0 +1,28 @@
From 869f514310b72169a294baa37f5a90a291f719f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 23 Aug 2018 11:51:47 +0200
Subject: [PATCH 3/3] xqmstats: Fix a file descriptor leak in main()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
xqmstats.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/xqmstats.c b/xqmstats.c
index cdac4a6..59b1d66 100644
--- a/xqmstats.c
+++ b/xqmstats.c
@@ -35,6 +35,7 @@ int main(int argc, char **argv)
if ((stats = fopen(XQMSTATS, "r")) == NULL) {
if ((stats = fopen(STATFILE, "r")) == NULL) {
errstr(_("The running kernel does not support XFS\n"));
+ fclose(xqm);
return 1;
}
}
--
2.14.4

View File

@ -10,7 +10,7 @@
Name: quota
Epoch: 1
Version: 4.04
Release: 9%{?dist}
Release: 10%{?dist}
Summary: System administration tools for monitoring users' disk usage
# quota_nld.c, quotaio_xfs.h: GPLv2
# bylabel.c copied from util-linux: GPLv2+
@ -83,6 +83,15 @@ Patch11: quota-4.04-rpc-Fix-wrong-limit-for-space-usage.patch
# tool output, proposed to upstream,
# <https://sourceforge.net/p/linuxquota/bugs/128/>
Patch12: quota-4.04-quota-1-Distinguish-between-none-quota-limits-and-no.patch
# Fix a descriptor leak, proposed to upstream,
# <https://sourceforge.net/p/linuxquota/bugs/129/>
Patch13: quota-4.04-convertquota-Fix-a-file-descriptor-leak-in-convert_e.patch
# Fix a descriptor leak, proposed to upstream,
# <https://sourceforge.net/p/linuxquota/bugs/129/>
Patch14: quota-4.04-quotackeck-Fix-a-directory-descriptor-leak-in-scan_d.patch
# Fix a descriptor leak, proposed to upstream,
# <https://sourceforge.net/p/linuxquota/bugs/129/>
Patch15: quota-4.04-xqmstats-Fix-a-file-descriptor-leak-in-main.patch
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: bash
@ -209,6 +218,9 @@ Linux/UNIX environment.
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
# Regenerate build scripts
autoreconf -f -i
@ -353,6 +365,9 @@ make check
%changelog
* Thu Aug 23 2018 Petr Pisar <ppisar@redhat.com> - 1:4.04-10
- Fix file descriptor leaks in error code paths
* Tue Jul 24 2018 Petr Pisar <ppisar@redhat.com> - 1:4.04-9
- Distinguish between none quota limits and no allocated resources in quota(1)
tool output