From patchwork Tue Nov 4 11:26:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xishi Qiu X-Patchwork-Id: 406522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id A24B014009E for ; Tue, 4 Nov 2014 22:26:48 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 6F93F9535A; Tue, 4 Nov 2014 11:26:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9RKgRCJeh9Jq; Tue, 4 Nov 2014 11:26:44 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 78A7B957C9; Tue, 4 Nov 2014 11:26:44 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id A8AE41C2369 for ; Tue, 4 Nov 2014 11:26:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id A419E88F60 for ; Tue, 4 Nov 2014 11:26:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AS6SEiajQrBy for ; Tue, 4 Nov 2014 11:26:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [119.145.14.66]) by fraxinus.osuosl.org (Postfix) with ESMTPS id CEC8F88C8B for ; Tue, 4 Nov 2014 11:26:41 +0000 (UTC) Received: from 172.24.2.119 (EHLO szxeml407-hub.china.huawei.com) ([172.24.2.119]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id AWP51188; Tue, 04 Nov 2014 19:26:36 +0800 (CST) Received: from [127.0.0.1] (10.177.25.179) by szxeml407-hub.china.huawei.com (10.82.67.94) with Microsoft SMTP Server id 14.3.158.1; Tue, 4 Nov 2014 19:26:29 +0800 Message-ID: <5458B7E4.9040307@huawei.com> Date: Tue, 4 Nov 2014 19:26:28 +0800 From: Xishi Qiu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Subject: [PATCH] add argument check in setenv() X-Originating-IP: [10.177.25.179] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020208.5458B7EC.00EF, ss=1, re=0.001, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 16f30351d8f3c6e83e0d85c836bc1834 Cc: Wang Nan X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" setenv() in glibc/eglibc will check the argument, like this, ... if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { __set_errno (EINVAL); return -1; } ... So add argument check in uclibc's setenv() too. Signed-off-by: Xishi Qiu --- libc/stdlib/setenv.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c index 00e3f3d..0ca6daf 100644 --- a/libc/stdlib/setenv.c +++ b/libc/stdlib/setenv.c @@ -116,6 +116,11 @@ static int __add_to_environ(const char *name, const char *value, int setenv(const char *name, const char *value, int replace) { + if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { + __set_errno (EINVAL); + return -1; + } + /* NB: setenv("VAR", NULL, 1) inserts "VAR=" string */ return __add_to_environ(name, value ? value : "", replace); }