[git commit branch/0.9.33] resolv: tiny shrinkage in /etc/hosts handling

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Thu Apr 26 20:37:12 UTC 2012


commit: http://git.uclibc.org/uClibc/commit/?id=bb938c203a2d6e140103e1def1946f86731dcb0a
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/0.9.33

-4b

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 libc/inet/resolv.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index e75e940..e738098 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1590,7 +1590,7 @@ parser_t * __open_etc_hosts(void)
 }
 
 #define MINTOKENS 2 /* ip address + canonical name */
-#define MAXTOKENS (MINTOKENS + MAXALIASES + 1)
+#define MAXTOKENS (MINTOKENS + MAXALIASES)
 #define HALISTOFF (sizeof(char*) * MAXTOKENS)
 #define INADDROFF (HALISTOFF + 2 * sizeof(char*))
 
@@ -1604,7 +1604,6 @@ int attribute_hidden __read_etc_hosts_r(
 		struct hostent **result,
 		int *h_errnop)
 {
-	char **alias;
 	char **tok = NULL;
 	struct in_addr *h_addr0 = NULL;
 	const size_t aliaslen = INADDROFF +
@@ -1634,12 +1633,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-1, MINTOKENS, "# \t", PARSE_NORMAL)) {
-		result_buf->h_aliases = alias = tok+1;
+	while (config_read(parser, &tok, MAXTOKENS, MINTOKENS, "# \t", PARSE_NORMAL)) {
+		result_buf->h_aliases = tok+1;
 		if (action == GETHOSTENT) {
 			/* Return whatever the next entry happens to be. */
 			break;
@@ -1648,8 +1646,11 @@ int attribute_hidden __read_etc_hosts_r(
 			if (strcmp(name, *tok) != 0)
 				continue;
 		} else { /* GET_HOSTS_BYNAME */
-			while (*alias) {
-				if (strcasecmp(name, *(alias++)) == 0)
+			int aliases = 0;
+			char **alias = tok + 1;
+			while (aliases < MAXALIASES) {
+				char *tmp = *(alias+aliases++);
+				if (tmp && strcasecmp(name, tmp) == 0)
 					goto found;
 			}
 			continue;


More information about the uClibc-cvs mailing list