From patchwork Fri Mar 8 20:46:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1053706 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-100513-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="QaEtzf9x"; 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 44GKKg1ZTRz9ryj for ; Sat, 9 Mar 2019 07:46:31 +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= KrO5uk61yiWPLCb50LMER5qq722Iy/RUfV/PVtJNSUiG+Izx6L+V7dLhzs06KkaK Ju/K7qZ28Za6DbQogmZNaG6S5HxapFxZJRyVNq3lskf+i4MlgKZey5eaJmojVDbl gxT8WUEWPFY2RMgWGlZx7TB+tSVpywUdHqJLhJhV1rw= 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=KG2ojn OPeML1f/i0bDsJN4IlaRs=; b=QaEtzf9xIo5JFPjDbqLeWbBoCqy1AY/W7HwPQi eQW772laNkdwxFBJAxJNzzl1cOnEMZ1GUVCCIu8XFHVhai9qdy1TqMVYudstSGhG /igTOcJqs+Nq4JKe2SMlTiT7pyzCGURbTi6r/yh7lL5J4b401SqsxEdNOte1zqKW IQI1Y= Received: (qmail 21571 invoked by alias); 8 Mar 2019 20:46:25 -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 21203 invoked by uid 89); 8 Mar 2019 20:46:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.7 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:12 +0100 To: libc-alpha@sourceware.org Subject: [PATCH] nss_dns: Adjust ns_name_ntop failure handling in getnetby* User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20190308204612.5537780DD6B5@oldenburg2.str.redhat.com> From: Florian Weimer If the function fails, the output buffer is not large enough. The function does not fail for any other reason. 2019-03-08 Florian Weimer * resolv/nss_dns/dns-network.c (getanswer_r): On ns_name_ntop failure, the buffer is always too small. diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c index 68266d57c9..9b75ac8233 100644 --- a/resolv/nss_dns/dns-network.c +++ b/resolv/nss_dns/dns-network.c @@ -324,19 +324,14 @@ getanswer_r (const querybuf *answer, int anslen, struct netent *result, { int n = __ns_name_unpack (answer->buf, end_of_message, cp, packtmp, sizeof packtmp); - if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1) - { - if (errno == EMSGSIZE) - goto too_small; - - n = -1; - } - - if (n > 0 && bp[0] == '.') - bp[0] = '\0'; - if (n < 0) goto bad_message; + if (__ns_name_ntop (packtmp, bp, linebuflen) < 0) + goto too_small; + + if (bp[0] == '.') + bp[0] = '\0'; + cp += n; if (end_of_message - cp < 10) @@ -355,16 +350,11 @@ getanswer_r (const querybuf *answer, int anslen, struct netent *result, { n = __ns_name_unpack (answer->buf, end_of_message, cp, packtmp, sizeof packtmp); - if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1) - { - if (errno == EMSGSIZE) - goto too_small; - - n = -1; - } - if (n < 0) goto bad_message; + if (__ns_name_ntop (packtmp, bp, linebuflen) < 0) + goto too_small; + cp += rdatalen; if (alias_pointer + 2 < &net_data->aliases[MAX_NR_ALIASES]) {