From patchwork Mon Mar 16 00:42:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 450358 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 A6FAB14009B for ; Mon, 16 Mar 2015 11:43:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=sourceware.org header.i=@sourceware.org header.b=uGsKqXzD; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type; q=dns; s=default; b= uQZrcw8OpN2e4/lvzNL7uNg+Z1Vi4/Azi4nShFGLmUHqqbmsWHEKZ405a6FS1tLV ThfylYwqMG21jbwhenD33hdg1z+HZWskkrjA1yzSQWFwc5wC1SbfNo5r/c4fnh4d UsMf3MO/rw823icaYKc1Jy+qVCJ/oOM3yrNS6eLaUvs= 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:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type; s=default; bh=+rve r+qzKBzpULwObW0R92xW37w=; b=uGsKqXzDcO598NTv5DQA3w6M21Q1Gcp0C0x2 Aol7WIp9QAPIk4fk3Dnf/vUdOojN352UvOpNq4n7OiZju+K15jDGolpu1+ZRBWFc F/aco7ICofO83lXfMV2pQOX2fJP7dcOlwkcTlck4sTUbAcsHvIly15XksmQyF8r4 URc4gh4= Received: (qmail 90966 invoked by alias); 16 Mar 2015 00:43:06 -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 90952 invoked by uid 89); 16 Mar 2015 00:43:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: smtp.cs.ucla.edu Message-ID: <55062712.4040104@cs.ucla.edu> Date: Sun, 15 Mar 2015 17:42:58 -0700 From: Paul Eggert User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Paul Pluzhnikov CC: Roland McGrath , Szabolcs Nagy , Joseph Myers , GLIBC Devel , "mtk@man7.org" Subject: Re: [patch] Error on setenv(..., NULL, ...) References: <55008721.1090200@arm.com> <55008DE0.8050805@cs.ucla.edu> <20150312215314.1B7CC2C3B8E@topped-with-meat.com> <55021AB7.1060905@cs.ucla.edu> <20150313170436.BF4C92C3B3B@topped-with-meat.com> <55031BC3.6070709@cs.ucla.edu> In-Reply-To: Paul Pluzhnikov wrote: > So it looks to me like the 2ecccaede9097f867284d352a881d8f226ba4fb7 is > quite broken, and should be reverted. I reverted it. Sorry about that; it had a horrible typo (!= vs ==). Does the attached (untested) patch work for you instead? It fixes the typo, and also pacifies GCC so that GCC does not issue the bogus warning. From 7d298c5558df36cf0e6a46940ace042c52284264 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 15 Mar 2015 17:38:10 -0700 Subject: [PATCH] * stdlib/setenv.c (__add_to_environ): Dump core quickly if setenv (..., NULL, ...) is called. This time, do it the right way, and pacify GCC with a pragma. --- ChangeLog | 4 ++++ stdlib/setenv.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c856f79..e61cc17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2015-03-15 Paul Eggert + * stdlib/setenv.c (__add_to_environ): + Dump core quickly if setenv (..., NULL, ...) is called. + This time, do it the right way, and pacify GCC with a pragma. + * stdlib/setenv.c (__add_to_environ): Revert previous change. 2015-03-14 Andreas Schwab diff --git a/stdlib/setenv.c b/stdlib/setenv.c index b60c4f0..184a8cd 100644 --- a/stdlib/setenv.c +++ b/stdlib/setenv.c @@ -19,6 +19,13 @@ # include #endif +/* Pacify GCC; see the commentary about VALLEN below. This is needed + at least through GCC 4.9.2. Pacify GCC for the entire file, as + there seems to be no way to pacify GCC selectively, only for the + place where it's needed. Do not use DIAG_IGNORE_NEEDS_COMMENT + here, as it's not defined yet. */ +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + #include #if !_LIBC # if !defined errno && !defined HAVE_ERRNO_DECL @@ -114,8 +121,17 @@ __add_to_environ (name, value, combined, replace) { char **ep; size_t size; + + /* Compute lengths before locking, so that the critical section is + less of a performance bottleneck. VALLEN is needed only if + COMBINED is null (unfortunately GCC is not smart enough to deduce + this; see the #pragma at the start of this file). Testing + COMBINED instead of VALUE causes setenv (..., NULL, ...) to dump + core now instead of corrupting memory later. */ const size_t namelen = strlen (name); - const size_t vallen = value != NULL ? strlen (value) + 1 : 0; + size_t vallen; + if (combined == NULL) + vallen = strlen (value) + 1; LOCK; -- 2.1.0