diff options
| author | christos <christos@NetBSD.org> | 2015-09-22 16:16:02 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2015-09-22 16:16:02 +0000 |
| commit | bbdf5017c5e4fe3348d233f5f7d52d306bd14945 (patch) | |
| tree | 4047f436c235f4c8593bcdbb07ee57d565640881 /lib/libc/net | |
| parent | aeac41085188217fc32af25e28275ef7dbec714f (diff) | |
- fix various leaks on error
- don't use the wrong error variable in switch
- always set the error return code
- return consistent errors when the input data cannot be handled.
Diffstat (limited to 'lib/libc/net')
| -rw-r--r-- | lib/libc/net/gethnamaddr.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/libc/net/gethnamaddr.c b/lib/libc/net/gethnamaddr.c index 6e86dfc63af..a83435ceb9c 100644 --- a/lib/libc/net/gethnamaddr.c +++ b/lib/libc/net/gethnamaddr.c @@ -1,4 +1,4 @@ -/* $NetBSD: gethnamaddr.c,v 1.91 2014/06/19 15:08:18 christos Exp $ */ +/* $NetBSD: gethnamaddr.c,v 1.92 2015/09/22 16:16:02 christos Exp $ */ /* * ++Copyright++ 1985, 1988, 1993 @@ -57,7 +57,7 @@ static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp "; #else -__RCSID("$NetBSD: gethnamaddr.c,v 1.91 2014/06/19 15:08:18 christos Exp $"); +__RCSID("$NetBSD: gethnamaddr.c,v 1.92 2015/09/22 16:16:02 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -244,6 +244,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, name_ok = res_dnok; break; default: + *he = NO_RECOVERY; return NULL; /* XXX should be abort(); */ } @@ -964,6 +965,7 @@ _dns_gethtbyname(void *rv, void *cb_data, va_list ap) res = __res_get_state(); if (res == NULL) { free(buf); + *info->he = NETDB_INTERNAL; return NS_NOTFOUND; } n = res_nsearch(res, name, C_IN, type, buf->buf, (int)sizeof(buf->buf)); @@ -978,7 +980,7 @@ _dns_gethtbyname(void *rv, void *cb_data, va_list ap) free(buf); __res_put_state(res); if (hp == NULL) - switch (h_errno) { + switch (*info->he) { case HOST_NOT_FOUND: return NS_NOTFOUND; case TRY_AGAIN: @@ -1026,35 +1028,31 @@ _dns_gethtbyaddr(void *rv, void *cb_data, va_list ap) ((unsigned int)uaddr[n] >> 4) & 0xf); if (advance > 0 && qp + advance < ep) qp += advance; - else { - *info->he = NETDB_INTERNAL; - return NS_NOTFOUND; - } - } - if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) { - *info->he = NETDB_INTERNAL; - return NS_NOTFOUND; + else + goto norecovery; } + if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) + goto norecovery; break; default: - return NS_UNAVAIL; + goto norecovery; } buf = malloc(sizeof(*buf)); if (buf == NULL) { - *info->he = NETDB_INTERNAL; - return NS_NOTFOUND; + goto nospc; } res = __res_get_state(); if (res == NULL) { free(buf); - return NS_NOTFOUND; + goto nospc; } n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf)); if (n < 0) { free(buf); debugprintf("res_nquery failed (%d)\n", res, n); __res_put_state(res); + *info->he = HOST_NOT_FOUND; return NS_NOTFOUND; } hp = getanswer(buf, n, qbuf, T_PTR, res, info->hp, info->buf, @@ -1080,8 +1078,10 @@ _dns_gethtbyaddr(void *rv, void *cb_data, va_list ap) hp->h_addr_list[1] = NULL; (void)memcpy(bf, uaddr, (size_t)info->hp->h_length); if (info->hp->h_addrtype == AF_INET && (res->options & RES_USE_INET6)) { - if (blen + NS_IN6ADDRSZ > info->buflen) + if (blen + NS_IN6ADDRSZ > info->buflen) { + __res_put_state(res); goto nospc; + } map_v4v6_address(bf, bf); hp->h_addrtype = AF_INET6; hp->h_length = NS_IN6ADDRSZ; @@ -1093,6 +1093,9 @@ _dns_gethtbyaddr(void *rv, void *cb_data, va_list ap) nospc: *info->he = NETDB_INTERNAL; return NS_UNAVAIL; +norecovery: + *info->he = NO_RECOVERY; + return NS_UNAVAIL; } #ifdef YP |
