From patchwork Sat May 30 07:52:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shengyong X-Patchwork-Id: 478416 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 B3B24140E63 for ; Sat, 30 May 2015 17:52:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=sourceware.org header.i=@sourceware.org header.b=sWCv2wu/; 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:content-type:content-transfer-encoding; q=dns; s= default; b=cWDBfjX+RRRtifB/+jda29zRCpXDNbGvpoDFRnUtIlqjpV3nLfkj2 IcCydXnykwocZZQCy/COhspsreNproXkTwW/JWGye2w+MROk98dIkB5yznyG9uow VkOdcN8X8XKTeu646c5inojHgawTz+gXzCbVrE7pdEPpUo2Gk6UWzQ= 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:content-type:content-transfer-encoding; s=default; bh=Y ytQ3df9hYNDrL2WVwwgHkwRh/Q=; b=sWCv2wu/A0YZTfLiIaygUySfEUyWl9UEm HM1LfaWpi33SzhmexD9TU9ilq9PCAJKcW2jXKVxAQcg9Lqm4AZfGrZTVACJQtRHE JhbyC7GiH862tvod67uAT6+37K3dUsuiWQF/F0y7csrwIvT1c+63BmG1f06n6hJQ Dcup4orKRc= Received: (qmail 101589 invoked by alias); 30 May 2015 07:52:33 -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 101575 invoked by uid 89); 30 May 2015 07:52:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: szxga03-in.huawei.com Message-ID: <55696C2D.5040200@huawei.com> Date: Sat, 30 May 2015 15:52:13 +0800 From: Sheng Yong User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: CC: Subject: getpwnam(NULL) get "segmentation fault" X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.55696C3A.00DF, ss=1, re=0.000, 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: 22ad4bccce9f1c0a49cc6806dd19035f Hi, When using getpwnam(), we found that if the parameter is NULL, the program would get a segmentation fault. I checked the glibc code, and found that parameter passed to function is defined as a macro ADD_PARAMS and its value is not checked before using. It seems serval functions under nss directory doing so. But segmentation fault is not friendly to users. Maybe we could add some parameter-check code before using theses parameters like the following. But I don't know if it is reasonable to do that. Any hint is appreciated. thanks, Sheng diff --git a/nss/getXXbyYY.c b/nss/getXXbyYY.c index 15fecf8..4ea7ee2 100644 --- a/nss/getXXbyYY.c +++ b/nss/getXXbyYY.c @@ -96,6 +96,8 @@ FUNCTION_NAME (ADD_PARAMS) /* Get lock. */ __libc_lock_lock (lock); + CHECK_PARAMS(); + if (buffer == NULL) { buffer_size = BUFLEN; diff --git a/pwd/getpwnam.c b/pwd/getpwnam.c index 9ec66d7..cb28279 100644 --- a/pwd/getpwnam.c +++ b/pwd/getpwnam.c @@ -25,5 +25,9 @@ #define ADD_PARAMS const char *name #define ADD_VARIABLES name #define BUFLEN NSS_BUFLEN_PASSWD +#define CHECK_PARAMS() do { \ + if (name == NULL) \ + return NULL; \ +} while (0) #include "../nss/getXXbyYY.c"