From patchwork Thu Dec 11 17:38:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Ellcey X-Patchwork-Id: 420191 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 7AE8114009B for ; Fri, 12 Dec 2014 04:39:02 +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:message-id:subject:from:reply-to:to:cc:date :in-reply-to:references:content-type:content-transfer-encoding :mime-version; q=dns; s=default; b=F/T+KUaBqQuUcep3XT6QXHrgmP3ES /4DIRLIXfvbHs++jVmto+9MEpzo/TsxWNKR1ACY4MjWgXr3tWZU4pqaUZz5PndjH egTFgfvLuGUMfW9/53Z2QrTRPWvbP5cSaMF7mmmsOt3QfqenepW7UulbhqK0QQ1v D2+Q3c6/oHc77E= 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:message-id:subject:from:reply-to:to:cc:date :in-reply-to:references:content-type:content-transfer-encoding :mime-version; s=default; bh=fPhb+4LOhuVWjXWD+k/rofM/glk=; b=iU+ OJSkCKiPBa9LGTRLO6D3JoejAp4oaJ/CV1WzA0Ex0Y10ImwgCpuGPpbhqoeuX+vs zm1UVFjjbfwjjjyIN7ictcMrY3UCTOUPRMFMj75NOwxLlpc7BTN5B3Ze/5gL4dpa lC5X3sgQi09iqfowLjnNfGbVz9m+sRtNFEIoZn8A= Received: (qmail 31655 invoked by alias); 11 Dec 2014 17:38:56 -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 31645 invoked by uid 89); 11 Dec 2014 17:38:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mailapp01.imgtec.com Message-ID: <1418319526.2196.150.camel@ubuntu-sellcey> Subject: Re: [Patch, MIPS] Fix uninitialized variable in inet/getnetgrent_r.c From: Steve Ellcey Reply-To: To: Joseph Myers CC: Date: Thu, 11 Dec 2014 09:38:46 -0800 In-Reply-To: References: <9615e42e-4783-4170-8702-042df4ce8d58@BAMAIL02.ba.imgtec.org> MIME-Version: 1.0 On Wed, 2014-12-10 at 21:33 +0000, Joseph Myers wrote: > On Wed, 10 Dec 2014, Steve Ellcey wrote: > > > I looked at the code and I don't think we can actually use an uninitialized > > fct variable (due to the use of the no_more variable) but the compiler doesn't > > seem to be able to figure that out. This fix is to just initialize fct to > > NULL. > > As previously discussed, we don't want to add such initializations to > quiet warnings. > > In this case, it looks like moving the while loop inside the "if (! > no_more)" ought to make it obvious to the compiler that fct can't be used > uninitialized. OK, Here is a new patch that puts the while loop inside the if statement. That does get rid of the warning. Other then indenting changes (and tweaking a comment so it doesn't wrap) that is the only change. Tested on MIPS with no regressions. OK for checkin? Steve Ellcey sellcey@imgtec.com 2014-12-11 Steve Ellcey * inet/getnetgrent_r.c: Move while loop to be inside if statement. diff --git a/inet/getnetgrent_r.c b/inet/getnetgrent_r.c index e101537..1f12ce9 100644 --- a/inet/getnetgrent_r.c +++ b/inet/getnetgrent_r.c @@ -281,8 +281,8 @@ __internal_getnetgrent_r (char **hostp, char **userp, char **domainp, { #ifdef USE_NSCD /* This bogus function pointer is a special marker left by - __nscd_setnetgrent to tell us to use the data it left - before considering any modules. */ + __nscd_setnetgrent to tell us to use the data it left + before considering any modules. */ if (datap->nip == (service_user *) -1l) fct = nscd_getnetgrent; else @@ -291,74 +291,73 @@ __internal_getnetgrent_r (char **hostp, char **userp, char **domainp, fct = __nss_lookup_function (datap->nip, "getnetgrent_r"); no_more = fct == NULL; } - } - - while (! no_more) - { - status = DL_CALL_FCT (*fct, (datap, buffer, buflen, &errno)); - if (status == NSS_STATUS_RETURN - /* The service returned a NOTFOUND, but there are more groups that we - need to resolve before we give up. */ - || (status == NSS_STATUS_NOTFOUND && datap->needed_groups != NULL)) + while (! no_more) { - /* This was the last one for this group. Look at next group - if available. */ - int found = 0; - while (datap->needed_groups != NULL && ! found) + status = DL_CALL_FCT (*fct, (datap, buffer, buflen, &errno)); + + if (status == NSS_STATUS_RETURN + /* The service returned a NOTFOUND, but there are more groups that + we need to resolve before we give up. */ + || (status == NSS_STATUS_NOTFOUND && datap->needed_groups != NULL)) { - struct name_list *tmp = datap->needed_groups; - datap->needed_groups = datap->needed_groups->next; - tmp->next = datap->known_groups; - datap->known_groups = tmp; + /* This was the last one for this group. Look at next group + if available. */ + int found = 0; + while (datap->needed_groups != NULL && ! found) + { + struct name_list *tmp = datap->needed_groups; + datap->needed_groups = datap->needed_groups->next; + tmp->next = datap->known_groups; + datap->known_groups = tmp; - found = __internal_setnetgrent_reuse (datap->known_groups->name, - datap, errnop); - } + found = __internal_setnetgrent_reuse (datap->known_groups->name, + datap, errnop); + } - if (found && datap->nip != NULL) - { - fct = __nss_lookup_function (datap->nip, "getnetgrent_r"); - if (fct != NULL) - continue; + if (found && datap->nip != NULL) + { + fct = __nss_lookup_function (datap->nip, "getnetgrent_r"); + if (fct != NULL) + continue; + } } - } - else if (status == NSS_STATUS_SUCCESS && datap->type == group_val) - { - /* The last entry was a name of another netgroup. */ - struct name_list *namep; - - /* Ignore if we've seen the name before. */ - for (namep = datap->known_groups; namep != NULL; - namep = namep->next) - if (strcmp (datap->val.group, namep->name) == 0) - break; - if (namep == NULL) - for (namep = datap->needed_groups; namep != NULL; - namep = namep->next) - if (strcmp (datap->val.group, namep->name) == 0) - break; - if (namep != NULL) - /* Really ignore. */ - continue; - - size_t group_len = strlen (datap->val.group) + 1; - namep = (struct name_list *) malloc (sizeof (struct name_list) - + group_len); - if (namep == NULL) - /* We are out of memory. */ - status = NSS_STATUS_RETURN; - else + else if (status == NSS_STATUS_SUCCESS && datap->type == group_val) { - namep->next = datap->needed_groups; - memcpy (namep->name, datap->val.group, group_len); - datap->needed_groups = namep; - /* And get the next entry. */ - continue; + /* The last entry was a name of another netgroup. */ + struct name_list *namep; + + /* Ignore if we've seen the name before. */ + for (namep = datap->known_groups; namep != NULL; + namep = namep->next) + if (strcmp (datap->val.group, namep->name) == 0) + break; + if (namep == NULL) + for (namep = datap->needed_groups; namep != NULL; + namep = namep->next) + if (strcmp (datap->val.group, namep->name) == 0) + break; + if (namep != NULL) + /* Really ignore. */ + continue; + + size_t group_len = strlen (datap->val.group) + 1; + namep = (struct name_list *) malloc (sizeof (struct name_list) + + group_len); + if (namep == NULL) + /* We are out of memory. */ + status = NSS_STATUS_RETURN; + else + { + namep->next = datap->needed_groups; + memcpy (namep->name, datap->val.group, group_len); + datap->needed_groups = namep; + /* And get the next entry. */ + continue; + } } + break; } - - break; } if (status == NSS_STATUS_SUCCESS) @@ -382,7 +381,7 @@ __getnetgrent_r (char **hostp, char **userp, char **domainp, __libc_lock_lock (lock); status = __internal_getnetgrent_r (hostp, userp, domainp, &dataset, - buffer, buflen, &errno); + buffer, buflen, &errno); __libc_lock_unlock (lock);