From 2bac7daa58da1a313bd452369b0508b31e146637 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 31 Jan 2019 18:49:58 +0100 Subject: nss_files: Fix /etc/aliases null pointer dereference [BZ #24059] If /etc/aliases ends with a continuation line (a line that starts with whitespace) which does not have a trailing newline character, the file parser would crash due to a null pointer dereference. Reviewed-by: Carlos O'Donell --- nss/nss_files/files-alias.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'nss/nss_files') diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c index 540eb9c..34d7aa8 100644 --- a/nss/nss_files/files-alias.c +++ b/nss/nss_files/files-alias.c @@ -333,6 +333,16 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result, can be ignored. */ first_unused[room_left - 1] = '\xff'; line = fgets_unlocked (first_unused, room_left, stream); + if (line == NULL) + { + /* Continuation line without any data and + without a newline at the end. Treat it as an + empty line and retry, reaching EOF once + more. */ + line = first_unused; + *line = '\0'; + continue; + } if (first_unused[room_left - 1] != '\xff') goto no_more_room; cp = strpbrk (line, "#\n"); -- cgit v1.1