From patchwork Wed Mar 11 18:48:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 449136 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 61EF614015A for ; Thu, 12 Mar 2015 05:48:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=sourceware.org header.i=@sourceware.org header.b=QlIebHg5; 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= xlLRSJDkZZO5RoqjEAZTmcSatbhj18S1B2SUeQ5yfGM6qURSgyvuM6Z/Y55kQTfZ ngT93DlyAGr6uvOH8r9RSf7DU4tvaB8jOyywZPoUIBJsXcZIlX7I4yH3sBN47jzu JuEqhApl5sdGmMGkkJzR6l5ZJ74I26Vdbwo8BnbAg50= 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=kBWc OOl8M490RcUQtWXOp5jLYA4=; b=QlIebHg5CQ6MF2+Or0/OW2ucJNIepAXFlw9C 7GEUrM0GJqwo0qjtMAZQbOw133KIbMq48Lhuzws1Ok8HBWni3u8Kqb0pZ2vBTAMM S4Eoa4JYp0pJ3TEjpU+CjuOjvt5zWMlY2wvqf+M6q8YeY4StoyQfbZXvT+MSFQAG 6mQTAcc= Received: (qmail 5331 invoked by alias); 11 Mar 2015 18:48:07 -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 5173 invoked by uid 89); 11 Mar 2015 18:48:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 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: <55008DE0.8050805@cs.ucla.edu> Date: Wed, 11 Mar 2015 11:48:00 -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 , Szabolcs Nagy CC: Joseph Myers , GLIBC Devel , Roland McGrath , "mtk@man7.org" Subject: Re: [patch] Error on setenv(..., NULL, ...) References: <55008721.1090200@arm.com> In-Reply-To: On 03/11/2015 11:26 AM, Paul Pluzhnikov wrote: > Where does it say that NULL name is allowed? It doesn't. But that's the FreeBSD behavior. FreeBSD setenv (..., NULL, ...) dumps core quickly because it calls strlen (NULL). How about if we do the same? It should be just as fast as what we do now, and it's safer and more compatible. Something like the attached untested patch, say. diff --git a/ChangeLog b/ChangeLog index 7360079..b9b40c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-11 Paul Eggert + + * stdlib/setenv.c (__add_to_environ): + Dump core quickly if setenv (..., NULL, ...) is called. + 2015-03-11 Paul Pluzhnikov [BZ #18043] diff --git a/stdlib/setenv.c b/stdlib/setenv.c index b60c4f0..f3de7e9 100644 --- a/stdlib/setenv.c +++ b/stdlib/setenv.c @@ -115,7 +115,13 @@ __add_to_environ (name, value, combined, replace) char **ep; size_t size; const size_t namelen = strlen (name); - const size_t vallen = value != NULL ? strlen (value) + 1 : 0; + size_t vallen; + + /* Test COMBINED, not VALUE, since VALLEN is needed only if COMBINED + is non-null. Also, testing COMBINED causes setenv (..., NULL, ...) + to dump core quickly instead of corrupting memory. */ + if (combined != NULL) + vallen = strlen (value) + 1; LOCK;