summaryrefslogtreecommitdiff
path: root/libc/inet/resolv.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-04-17 17:54:09 +0200
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-04-17 18:30:34 +0200
commitdcb6ac13546486099fd1c5fb83771cb69f2a16b7 (patch)
treeb1958ed524a4c40409afa2c035b8e6bd8ac74288 /libc/inet/resolv.c
parent238d11fd33fe85444fffc0cdd1a07cc70466a686 (diff)
resolv: Fix /etc/hosts for more than MAXALIASES aliases
PR networking/4916 Reserve space for the terminating 0 alias and zero out the scratch-buffer so the last entry of the alias list is empty. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc/inet/resolv.c')
-rw-r--r--libc/inet/resolv.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index a730584ee..0ce1acdaf 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1590,8 +1590,8 @@ parser_t * __open_etc_hosts(void)
return parser;
}
-#define MINTOKENS 2 //dotted ip address + canonical name
-#define MAXTOKENS (MINTOKENS + MAXALIASES)
+#define MINTOKENS 2 /* ip address + canonical name */
+#define MAXTOKENS (MINTOKENS + MAXALIASES + 1)
#define HALISTOFF (sizeof(char*) * MAXTOKENS)
#define INADDROFF (HALISTOFF + 2 * sizeof(char*))
@@ -1636,10 +1636,11 @@ int attribute_hidden __read_etc_hosts_r(
*/
parser->data = buf;
parser->data_len = aliaslen;
+ memset(buf, '\0', aliaslen); /* make sure alias list is terminated */
parser->line_len = buflen - aliaslen;
*h_errnop = HOST_NOT_FOUND;
/* <ip>[[:space:]][<aliases>] */
- while (config_read(parser, &tok, MAXTOKENS, MINTOKENS, "# \t", PARSE_NORMAL)) {
+ while (config_read(parser, &tok, MAXTOKENS-1, MINTOKENS, "# \t", PARSE_NORMAL)) {
result_buf->h_aliases = alias = host_aliases = tok+1;
if (action == GETHOSTENT) {
/* Return whatever the next entry happens to be. */