From patchwork Mon Jan 4 04:07:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoming Ni X-Patchwork-Id: 41615 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8AFA33858002; Mon, 4 Jan 2021 04:07:57 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by sourceware.org (Postfix) with ESMTPS id AB5D63858001 for ; Mon, 4 Jan 2021 04:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AB5D63858001 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nixiaoming@huawei.com Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4D8MWh5nlKzl0rD; Mon, 4 Jan 2021 12:06:40 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Mon, 4 Jan 2021 12:07:41 +0800 From: Xiaoming Ni To: , , , , , Subject: [PATCH v2] setrlimit/getrlimit: Use __nonnull to avoid null pointer Date: Mon, 4 Jan 2021 12:07:38 +0800 Message-ID: <20210104040738.75761-1-nixiaoming@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_MANYTO, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wangle6@huawei.com, nixiaoming@huawei.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Add __nonnull((2)) to the setrlimit()/getrlimit() function declaration to avoid null pointer access. ----- v2 According to the suggestions of the Adhemerval Zanella and Zack Weinberg: use __nonnull() to check null pointers in the compilation phase. do not add pointer check code to setrlimit()/getrlimit(). The validity of the "resource" parameter is checked in the syscall. v1 https://public-inbox.org/libc-alpha/20201230114131.47589-1-nixiaoming@huawei.com/ ----- Reviewed-by: Adhemerval Zanella --- include/sys/resource.h | 4 ++-- resource/sys/resource.h | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/sys/resource.h b/include/sys/resource.h index 2235b020fc..21d3908714 100644 --- a/include/sys/resource.h +++ b/include/sys/resource.h @@ -126,13 +126,13 @@ libc_hidden_proto (__getrlimit64); /* Now define the internal interfaces. */ extern int __getrlimit (enum __rlimit_resource __resource, - struct rlimit *__rlimits); + struct rlimit *__rlimits) __nonnull ((2)); libc_hidden_proto (__getrlimit) extern int __getrusage (enum __rusage_who __who, struct rusage *__usage) attribute_hidden; extern int __setrlimit (enum __rlimit_resource __resource, - const struct rlimit *__rlimits); + const struct rlimit *__rlimits) __nonnull ((2)); libc_hidden_proto (__setrlimit); #if __TIMESIZE == 64 diff --git a/resource/sys/resource.h b/resource/sys/resource.h index 4edafb50d5..41aa42daa4 100644 --- a/resource/sys/resource.h +++ b/resource/sys/resource.h @@ -48,18 +48,19 @@ typedef int __priority_which_t; Returns 0 if successful, -1 if not (and sets errno). */ #ifndef __USE_FILE_OFFSET64 extern int getrlimit (__rlimit_resource_t __resource, - struct rlimit *__rlimits) __THROW; + struct rlimit *__rlimits) __THROW __nonnull ((2)); #else # ifdef __REDIRECT_NTH extern int __REDIRECT_NTH (getrlimit, (__rlimit_resource_t __resource, - struct rlimit *__rlimits), getrlimit64); + struct rlimit *__rlimits), getrlimit64) + __nonnull ((2)); # else # define getrlimit getrlimit64 # endif #endif #ifdef __USE_LARGEFILE64 extern int getrlimit64 (__rlimit_resource_t __resource, - struct rlimit64 *__rlimits) __THROW; + struct rlimit64 *__rlimits) __THROW __nonnull ((2)); #endif /* Set the soft and hard limits for RESOURCE to *RLIMITS. @@ -67,19 +68,20 @@ extern int getrlimit64 (__rlimit_resource_t __resource, Return 0 if successful, -1 if not (and sets errno). */ #ifndef __USE_FILE_OFFSET64 extern int setrlimit (__rlimit_resource_t __resource, - const struct rlimit *__rlimits) __THROW; + const struct rlimit *__rlimits) __THROW __nonnull ((2)); #else # ifdef __REDIRECT_NTH extern int __REDIRECT_NTH (setrlimit, (__rlimit_resource_t __resource, const struct rlimit *__rlimits), - setrlimit64); + setrlimit64) __nonnull ((2)); # else # define setrlimit setrlimit64 # endif #endif #ifdef __USE_LARGEFILE64 extern int setrlimit64 (__rlimit_resource_t __resource, - const struct rlimit64 *__rlimits) __THROW; + const struct rlimit64 *__rlimits) __THROW + __nonnull ((2)); #endif /* Return resource usage information on process indicated by WHO