From e95c6f61920a0f9237cfb292fa44ad500e1df09b Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 14 Aug 2018 10:52:06 +0200 Subject: 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. --- nss/nss_files/files-alias.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'nss/nss_files') diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c index cfd34b66b9..35b0bfc5d2 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) -- cgit 1.4.1