From owner-freebsd-current@FreeBSD.ORG Sun Sep 9 23:17:40 2007 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1299A16A418 for ; Sun, 9 Sep 2007 23:17:40 +0000 (UTC) (envelope-from taku@tackymt.homeip.net) Received: from basalt.tackymt.homeip.net (unknown [IPv6:2001:3e0:577:0:20d:61ff:fecc:2253]) by mx1.freebsd.org (Postfix) with ESMTP id B558313C428 for ; Sun, 9 Sep 2007 23:17:39 +0000 (UTC) (envelope-from taku@tackymt.homeip.net) Received: from localhost (localhost [127.0.0.1]) by basalt.tackymt.homeip.net (Postfix) with ESMTP id 3F3C310749 for ; Mon, 10 Sep 2007 08:17:39 +0900 (JST) Received: from basalt.tackymt.homeip.net ([127.0.0.1]) by localhost (basalt.tackymt.homeip.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 50583-01 for ; Mon, 10 Sep 2007 08:17:37 +0900 (JST) Received: from biotite (unknown [IPv6:2001:3e0:577:0:216:cfff:febc:1472]) by basalt.tackymt.homeip.net (Postfix) with ESMTP for ; Mon, 10 Sep 2007 08:17:37 +0900 (JST) Date: Mon, 10 Sep 2007 08:17:36 +0900 From: "YAMAMOTO, Taku" To: freebsd-current@freebsd.org Message-Id: <20070910081736.45268f60.taku@tackymt.homeip.net> In-Reply-To: <20070910081425.3c45bca7.taku@tackymt.homeip.net> References: <20070910081425.3c45bca7.taku@tackymt.homeip.net> Organization: Trans New Technology, Inc. X-Mailer: Sylpheed 2.4.4 (GTK+ 2.10.14; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Mon__10_Sep_2007_08_17_36_+0900_prmCFf2l=WNuJLww" X-Virus-Scanned: amavisd-new at tackymt.homeip.net Subject: Follow-up: setenv() doesn't export unsetenv()ed variables to environ X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Sep 2007 23:17:40 -0000 This is a multi-part message in MIME format. --Multipart=_Mon__10_Sep_2007_08_17_36_+0900_prmCFf2l=WNuJLww Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Ouch, the testcase had got stripped due to inappropriate MIME type. On Mon, 10 Sep 2007 08:14:25 +0900 "YAMAMOTO, Taku" wrote: > Greetings, > > I found a regression in src/lib/libc/stdlib/getenv.c during tracking > strange behaviour of the sshguard-pf. > > In short, setenv() doesn't add an entry to environ[] if the name was > once removed by unsetenv(). > > I'm suspecting the function __setenv() lacks care of the case to reuse > a deactivated entry and it needs the following change: > > --- lib/libc/stdlib/getenv.c.orig 2007-07-21 08:30:13.000000000 +0900 > +++ lib/libc/stdlib/getenv.c 2007-09-10 08:07:22.732672106 +0900 > @@ -492,7 +492,7 @@ __setenv(const char *name, size_t nameLe > newEnvActive++; > > /* No need to rebuild environ if the variable was reused. */ > - if (reuse) > + if (reuse && newEnvActive == envActive) > return (0); > else > return (__rebuild_environ(newEnvActive)); > > > A small testcase is attached. > It should emit: > expecting "foo": foo > expecting "bar": bar > > With current broken setenv(), it would emit: > expecting "foo": foo > expecting "bar": > > > -- > -|-__ YAMAMOTO, Taku > | __ < > > - A chicken is an egg's way of producing more eggs. - > -- -|-__ 山本 拓 / YAMAMOTO, Taku | __ < - A chicken is an egg's way of producing more eggs. - --Multipart=_Mon__10_Sep_2007_08_17_36_+0900_prmCFf2l=WNuJLww Content-Type: text/plain; name="setenvtest.c" Content-Disposition: attachment; filename="setenvtest.c" Content-Transfer-Encoding: 7bit #include #include #include int main(void) { if (setenv("HOGE", "foo", 1)) warn("setenv(1st)"); system("echo 'expecting \"foo\":' $HOGE"); if (unsetenv("HOGE")) warn("unsetenv(1st)"); if (setenv("HOGE", "bar", 1)) warn("setenv(2nd)"); system("echo 'expecting \"bar\":' $HOGE"); return 0; } --Multipart=_Mon__10_Sep_2007_08_17_36_+0900_prmCFf2l=WNuJLww--