From patchwork Thu Mar 20 14:48:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 191 X-Patchwork-Delegate: siddhesh@gotplt.org Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (caibbdcaabij.dreamhost.com [208.113.200.189]) by wilcox.dreamhost.com (Postfix) with ESMTP id BB075360141 for ; Thu, 20 Mar 2014 07:48:15 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14307373) id 61CE84FABE06; Thu, 20 Mar 2014 07:48:15 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx22.g.dreamhost.com 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 homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 344AE4FA3B24 for ; Thu, 20 Mar 2014 07:48:15 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=Y08d7cN6mlWFC+QZDbT4tx9SgxR8U jIQoTiD3DhpNobM2T7ek8AzVhpgs/OVqvBzyyuUiibrpvZqNmrE84XpiEvrNS2/b YGP+0FQvAQaug9TX+VkIDia1Gc6cvXQCEEQ6sLTAURDtx0FGtDotl4/SqoHJsLRb 1SlgWPDBNDTIVY= 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:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=5ChYAN5CpqMSVB9/kgmXJDRc0Oc=; b=KIU 05WbY9HEm3saVdDtW7cSGzPTW44otwBsVcQG4XNPh7TY/d0VTzgFT5tcg/s8b7U5 lPZPsfVgyJw2Q9J4uLzAVX3eFd8Sur4CPNXCIcljVHlVXq+YNKn4Sygyfe1/wYte psLJiLHEox+fN4Rbeqc+8z2Ml9xAO5gaoMGKC8o0= Received: (qmail 8267 invoked by alias); 20 Mar 2014 14:48:12 -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 8232 invoked by uid 89); 20 Mar 2014 14:48:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx2.suse.de From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Fix use of half-initialized result in resolver when using nscd X-Yow: Hello? Enema Bondage? I'm calling because I want to be happy, I guess.. Date: Thu, 20 Mar 2014 15:48:04 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-DH-Original-To: glibc@patchwork.siddhesh.in This fixes a bug in the way the results from __nscd_getai are collected: for every returned result a new entry is first added to the gaih_addrtuple list, but if that result doesn't match the request this entry remains uninitialized. So for this non-matching result an extra result with uninitialized content is returned. Andreas. * sysdeps/posix/getaddrinfo.c (gaih_inet): Properly skip over non-matching result from nscd. --- sysdeps/posix/getaddrinfo.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index e1a399b..3385bed 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -710,6 +710,14 @@ gaih_inet (const char *name, const struct gaih_service *service, struct gaih_addrtuple *addrfree = addrmem; for (int i = 0; i < air->naddrs; ++i) { + if (!((air->family[i] == AF_INET + && req->ai_family == AF_INET6 + && (req->ai_flags & AI_V4MAPPED) != 0) + || req->ai_family == AF_UNSPEC + || air->family[i] == req->ai_family)) + /* Skip over non-matching result. */ + continue; + socklen_t size = (air->family[i] == AF_INET ? INADDRSZ : IN6ADDRSZ); if (*pat == NULL)