From owner-svn-src-head@FreeBSD.ORG Wed Jul 17 08:36:55 2013 Return-Path: Delivered-To: svn-src-head@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 1F655671; Wed, 17 Jul 2013 08:36:55 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id B9B03D0E; Wed, 17 Jul 2013 08:36:53 +0000 (UTC) Received: from porto.starpoint.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id LAA28670; Wed, 17 Jul 2013 11:36:52 +0300 (EEST) (envelope-from avg@FreeBSD.org) Received: from localhost ([127.0.0.1]) by porto.starpoint.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1UzNEB-000PrQ-Nd; Wed, 17 Jul 2013 11:36:51 +0300 Message-ID: <51E6576C.6010000@FreeBSD.org> Date: Wed, 17 Jul 2013 11:35:56 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130708 Thunderbird/17.0.7 MIME-Version: 1.0 To: Andrey Chernov Subject: Re: svn commit: r253380 - head/lib/libc/stdlib References: <201307160726.r6G7QlwE045679@svn.freebsd.org> <51E61950.5090206@freebsd.org> <51E62219.1090006@freebsd.org> <51E62B37.8080900@freebsd.org> In-Reply-To: <51E62B37.8080900@freebsd.org> X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jul 2013 08:36:55 -0000 on 17/07/2013 08:27 Andrey Chernov said the following: > On 17.07.2013 8:48, Andrey Chernov wrote: >> On 17.07.2013 8:10, Andrey Chernov wrote: >>> On 16.07.2013 11:26, Andriy Gapon wrote: >>>> Modified: head/lib/libc/stdlib/getenv.c >>>> ============================================================================== >>>> --- head/lib/libc/stdlib/getenv.c Tue Jul 16 06:50:22 2013 (r253379) >>>> +++ head/lib/libc/stdlib/getenv.c Tue Jul 16 07:26:46 2013 (r253380) >>>> @@ -505,7 +505,7 @@ __setenv(const char *name, size_t nameLe >>>> envVars[envNdx].valueSize = valueLen; >>>> >>>> /* Save name of name/value pair. */ >>>> - env = stpcpy(envVars[envNdx].name, name); >>>> + env = stpncpy(envVars[envNdx].name, name, nameLen); >>>> if ((envVars[envNdx].name)[nameLen] != '=') >>>> env = stpcpy(env, "="); >>>> } >>>> >>> >>> I am not sure what you are trying to fix, but you just made next line >>> condition unpredictable random, since (envVars[envNdx].name)[nameLen] is >>> never filled now and there is freshly malloced memory content, which is >>> picked for != '=' comparison. >>> >>> Please back it out or fix. >> >> If I understand that right, correct version will be: >> >> env = stpncpy(envVars[envNdx].name, name, nameLen); >> env = stpcpy(env, "="); >> >> Condition check is not needed. > > Microoptimized: > > env = stpncpy(envVars[envNdx].name, name, nameLen); > *env++ = '='; > In fact, I think that the currently committed code is not functionally broken, just weird. It is equivalent to: x = unitialized_value; if (x != X) x = X; /* else assert(x == X); */ which should be completely equivalent to just x = X; despite x starting out with random junk. -- Andriy Gapon