about summary refs log tree commit diff
path: root/nss/nss_files
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2019-01-31 18:49:58 +0100
committerFlorian Weimer <fweimer@redhat.com>2019-01-31 18:49:58 +0100
commit2bac7daa58da1a313bd452369b0508b31e146637 (patch)
treecb26cc3d34519adb5110c443400ff47b3c3cc00b /nss/nss_files
parentde44ab67aa4eec369deea828733567c35a0611c0 (diff)
downloadglibc-2bac7daa58da1a313bd452369b0508b31e146637.tar.gz
glibc-2bac7daa58da1a313bd452369b0508b31e146637.tar.xz
glibc-2bac7daa58da1a313bd452369b0508b31e146637.zip
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 <carlos@redhat.com>
Diffstat (limited to 'nss/nss_files')
-rw-r--r--nss/nss_files/files-alias.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
index 540eb9c678..34d7aa84cc 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");