summaryrefslogtreecommitdiff
path: root/nss
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-04-05 00:45:20 +0000
committerUlrich Drepper <drepper@redhat.com>1997-04-05 00:45:20 +0000
commiteb0740ad73b483114b5bb9a45f06288d65263300 (patch)
tree192cdd38eff20763ed7b1af2b1187e74929afed0 /nss
parent9106c38136e580b832b75b4f54e7e8dceb591455 (diff)
Correct handling of overflow in reading trailing list.
Diffstat (limited to 'nss')
-rw-r--r--nss/nss_files/files-parse.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c
index 2e84d762f0..acf673da90 100644
--- a/nss/nss_files/files-parse.c
+++ b/nss/nss_files/files-parse.c
@@ -1,5 +1,5 @@
/* Common code for file-based database parsers in nss_files module.
- Copyright (C) 1996 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -152,7 +152,7 @@ parse_line (char *line, struct STRUCTURE *result, \
if (list) \
result->TRAILING_LIST_MEMBER = list; \
else \
- return 0; \
+ return -1; /* -1 indicates we ran out of space. */ \
}
static inline char **
@@ -189,29 +189,26 @@ parse_list (char *line, struct parser_data *data, size_t datalen)
if (*line == '\0')
break;
+ /* Skip leading white space. This might not be portable but useful. */
+ while (isspace (*line))
+ ++line;
+
elt = line;
while (1)
{
- if (TRAILING_LIST_SEPARATOR_P (*line))
- {
- *p++ = elt;
- *line = '\0';
- do
- ++line;
- while (isspace (*line));
- elt = line;
- }
- else if (*line == '\0')
+ if (*line == '\0' || TRAILING_LIST_SEPARATOR_P (*line))
{
- /* End of the line. */
+ /* End of the next entry. */
if (line > elt)
- /* Last element. */
+ /* We really found some data. */
*p++ = elt;
- *line = '\0';
+
+ /* Terminate string if necessary. */
+ if (*line != '\0')
+ *line++ = '\0';
break;
}
- else
- ++line;
+ ++line;
}
}
*p = NULL;