From patchwork Fri Mar 8 20:46:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1053707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-100514-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="vzNK5t13"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44GKKq2pgWz9ryj for ; Sat, 9 Mar 2019 07:46:39 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= PA6wnwFU1CQ4PftN5tm3lH056D0+LD22cwRPWnuzcgabYFdaYMWhCXX4rP+CGlHh 11IrG5RpyM+uVy/LgFD8RBhXoSVQSZYBsh/PwbQOBkYS7UO5ol79f2D20LavSRr2 lyoMb2bYugQN7vhwBcUwEXZZY1/IVyBAfVOY5+owIg8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=1nlt0q EuQpEkH82gZblrAAiHW2U=; b=vzNK5t1301rVFZTYD38EyTsb3+yJPpQ6loS4ax UARmc9ZmN30SU0OHsW4OWa1e0Qs3RFItrBFuhcEnRhreMzzQJRLBcvNJKLAFqYUG bSMaEdM+gyWKEQEGbjXRsAdUUBUDEoiKMUz/1tbkHuk+pQs35s36CnqDQDE089YB j/lyw= Received: (qmail 22562 invoked by alias); 8 Mar 2019 20:46:31 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 22449 invoked by uid 89); 8 Mar 2019 20:46:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Date: Fri, 08 Mar 2019 21:46:25 +0100 To: libc-alpha@sourceware.org Subject: [PATCH] nss_dns: Adjust ns_name_ntop calls for gethostby*, getaddrinfo User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20190308204625.7864F80DD6B5@oldenburg2.str.redhat.com> From: Florian Weimer ns_name_ntop failure always means that the output buffer is not large enough. 2019-03-08 Florian Weimer * resolv/nss_dns/dns-host.c (getanswer_r, gaih_getanswer_slice): On ns_name_ntop failure, the buffer is always too small. diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c index a18b8a6bf4..f04e08016c 100644 --- a/resolv/nss_dns/dns-host.c +++ b/resolv/nss_dns/dns-host.c @@ -698,23 +698,18 @@ getanswer_r (struct resolv_context *ctx, n = __ns_name_unpack (answer->buf, end_of_message, cp, packtmp, sizeof packtmp); - if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1) + if (__glibc_unlikely (n < 0)) { - if (__glibc_unlikely (errno == EMSGSIZE)) - goto too_small; - - n = -1; + *errnop = errno; + *h_errnop = NO_RECOVERY; + return NSS_STATUS_UNAVAIL; } + if (__ns_name_ntop (packtmp, bp, linebuflen) < 0) + goto too_small; - if (n > 0 && bp[0] == '.') + if (bp[0] == '.') bp[0] = '\0'; - if (__glibc_unlikely (n < 0)) - { - *errnop = errno; - *h_errnop = NO_RECOVERY; - return NSS_STATUS_UNAVAIL; - } if (__glibc_unlikely (name_ok (bp) == 0)) { errno = EBADMSG; @@ -761,15 +756,16 @@ getanswer_r (struct resolv_context *ctx, n = __ns_name_unpack (answer->buf, end_of_message, cp, packtmp, sizeof packtmp); - if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1) + if (n < 0) { - if (__glibc_unlikely (errno == EMSGSIZE)) - goto too_small; - - n = -1; + ++had_error; + continue; } - if (__glibc_unlikely (n < 0 || (*name_ok) (bp) == 0)) + if (__ns_name_ntop (packtmp, bp, linebuflen) < 0) + goto too_small; + + if (__glibc_unlikely ((*name_ok) (bp) == 0)) { ++had_error; continue; @@ -892,15 +888,14 @@ getanswer_r (struct resolv_context *ctx, n = __ns_name_unpack (answer->buf, end_of_message, cp, packtmp, sizeof packtmp); - if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1) + if (n < 0) { - if (__glibc_unlikely (errno == EMSGSIZE)) - goto too_small; - - n = -1; + ++had_error; + break; } - - if (__glibc_unlikely (n < 0 || res_hnok (bp) == 0)) + if (__ns_name_ntop (packtmp, bp, linebuflen) < 0) + goto too_small; + if (__glibc_unlikely (res_hnok (bp) == 0)) { ++had_error; break; @@ -1032,27 +1027,22 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname, u_char packtmp[NS_MAXCDNAME]; int n = __ns_name_unpack (answer->buf, end_of_message, cp, packtmp, sizeof packtmp); + if (__glibc_unlikely (n < 0)) + { + *errnop = errno; + *h_errnop = NO_RECOVERY; + return NSS_STATUS_UNAVAIL; + } /* We unpack the name to check it for validity. But we do not need it later. */ - if (n != -1 && __ns_name_ntop (packtmp, buffer, buflen) == -1) + if (__ns_name_ntop (packtmp, buffer, buflen) < 0) { - if (__glibc_unlikely (errno == EMSGSIZE)) - { - too_small: - *errnop = ERANGE; - *h_errnop = NETDB_INTERNAL; - return NSS_STATUS_TRYAGAIN; - } - - n = -1; + too_small: + *errnop = ERANGE; + *h_errnop = NETDB_INTERNAL; + return NSS_STATUS_TRYAGAIN; } - if (__glibc_unlikely (n < 0)) - { - *errnop = errno; - *h_errnop = NO_RECOVERY; - return NSS_STATUS_UNAVAIL; - } if (__glibc_unlikely (res_hnok (buffer) == 0)) { errno = EBADMSG; @@ -1078,15 +1068,14 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname, { n = __ns_name_unpack (answer->buf, end_of_message, cp, packtmp, sizeof packtmp); - if (n != -1 && - (h_namelen = __ns_name_ntop (packtmp, buffer, buflen)) == -1) + if (n < 0) { - if (__glibc_unlikely (errno == EMSGSIZE)) - goto too_small; - - n = -1; + ++had_error; + continue; } - if (__glibc_unlikely (n < 0 || res_hnok (buffer) == 0)) + if ((h_namelen = __ns_name_ntop (packtmp, buffer, buflen)) < 0) + goto too_small; + if (__glibc_unlikely (res_hnok (buffer) == 0)) { ++had_error; continue;