From owner-svn-src-all@FreeBSD.ORG Wed Jul 17 05:27:30 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 86946161 for ; Wed, 17 Jul 2013 05:27:30 +0000 (UTC) (envelope-from mailer-daemon@vniz.net) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com [209.85.215.45]) by mx1.freebsd.org (Postfix) with ESMTP id 0176D660 for ; Wed, 17 Jul 2013 05:27:29 +0000 (UTC) Received: by mail-la0-f45.google.com with SMTP id fr10so1184406lab.18 for ; Tue, 16 Jul 2013 22:27:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:openpgp:content-type :content-transfer-encoding:x-gm-message-state; bh=S9qmfx/YL5Tf4mjyHQkKU1jxOTafwg4kXpfEJGm9c18=; b=R23HE5PVZzjxBRh/5bjJBsqLqWHhcjuQJgrE3i+miSLNK4IwqN97aOlHhDoj7KMfON UdN5IkNiq290WE+bRhfGveVZJKqAUaQPdks+t9kpaxJ6ip/crZZEg9jdPe+I/LokC9vX VoSFJx8bHIiQQ34V68hbV609S7GCF4pstn9CkhumQKqUP6lyonXo4ZYcfDTYFB9+ycy7 ANsF2NF1VavUg0IErG4enGKC8FpqMmEZDbUxGtX0844cZAU2xjG29JncHnQuxIYue7TT FOk6aOf+fYCYfO/yKiD+tcXLn4NPhrjZaEHdhVeKIICKPVFfb2u3OFtjSNol+JBihHj8 XP7Q== X-Received: by 10.152.2.168 with SMTP id 8mr2124912lav.69.1374038843036; Tue, 16 Jul 2013 22:27:23 -0700 (PDT) Received: from [192.168.1.2] ([89.169.173.68]) by mx.google.com with ESMTPSA id m1sm1706463lag.3.2013.07.16.22.27.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Jul 2013 22:27:22 -0700 (PDT) Message-ID: <51E62B37.8080900@freebsd.org> Date: Wed, 17 Jul 2013 09:27:19 +0400 From: Andrey Chernov User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Andriy Gapon Subject: Re: svn commit: r253380 - head/lib/libc/stdlib References: <201307160726.r6G7QlwE045679@svn.freebsd.org> <51E61950.5090206@freebsd.org> <51E62219.1090006@freebsd.org> In-Reply-To: <51E62219.1090006@freebsd.org> OpenPGP: id=964474DD Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQn5XNfob7lT3y20tvan7CbaF05QoqjCcWGljA+lXn/eaixfp6wDX9ViWgciHwh1QhTBWcU4 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jul 2013 05:27:30 -0000 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++ = '='; -- http://ache.vniz.net/ bitcoin:1G6ugdNY6e5jx1GVnAU2ntj2NEfmjKG85r