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: 332205 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 EB0972C00A0 for ; Fri, 21 Mar 2014 01:48:18 +1100 (EST) 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=TEJ4bLjGNDQxQHGBXU9nvmuS9cWzH LkKxtTBm6FyYv+TW4QLbcFnjfDqN3EfKu36WxaMqlJF/RA8N941aBmln8a81hKat g61FnYftgwUAeW3lpUY2liM+xnwfflL8kL+0Qb1JmPw1rkJp4udmGBPFXVSGkseC 5l/g8Jm1DOhXTo= 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=xRg b9Xi2OM4CqYXOxECg9C4YjTt/7ps9U5Ra4BhHjjH42T8Gv0v7qz/F6YIM5XeZPfn UGoAMpJa1uNly8F7Q8es8pPRfm2i74w56FCyXtbT47dNmATf37FaAFPILnw5jxBx 4bS0DrTOyhLBXTawZpXMNvaP9QKe6u7qQddtlEXU= 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 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)