aboutsummaryrefslogtreecommitdiff
path: root/nss/nss_files/files-alias.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2018-08-14 10:52:06 +0200
committerFlorian Weimer <fweimer@redhat.com>2018-08-14 10:52:06 +0200
commite95c6f61920a0f9237cfb292fa44ad500e1df09b (patch)
tree5e0b22cbbb895a01a8a92741929be1051d752c95 /nss/nss_files/files-alias.c
parent2d7acfac3ebf266dcbc82d0d6cc576f626953a03 (diff)
downloadglibc-e95c6f61920a0f9237cfb292fa44ad500e1df09b.zip
glibc-e95c6f61920a0f9237cfb292fa44ad500e1df09b.tar.gz
glibc-e95c6f61920a0f9237cfb292fa44ad500e1df09b.tar.bz2
nss_files: Fix file stream leak in aliases lookup [BZ #23521]
In order to get a clean test case, it was necessary to fix partially fixed bug 23522 as well.
Diffstat (limited to 'nss/nss_files/files-alias.c')
-rw-r--r--nss/nss_files/files-alias.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
index cfd34b6..35b0bfc 100644
--- a/nss/nss_files/files-alias.c
+++ b/nss/nss_files/files-alias.c
@@ -221,6 +221,13 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result,
{
while (! feof_unlocked (listfile))
{
+ if (room_left < 2)
+ {
+ free (old_line);
+ fclose (listfile);
+ goto no_more_room;
+ }
+
first_unused[room_left - 1] = '\xff';
line = fgets_unlocked (first_unused, room_left,
listfile);
@@ -229,6 +236,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result,
if (first_unused[room_left - 1] != '\xff')
{
free (old_line);
+ fclose (listfile);
goto no_more_room;
}
@@ -256,6 +264,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result,
+ __alignof__ (char *)))
{
free (old_line);
+ fclose (listfile);
goto no_more_room;
}
room_left -= ((first_unused - cp)