From patchwork Sun Mar 31 17:44:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Kharlamov X-Patchwork-Id: 1071852 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-101057-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="dgp6wV/+"; dkim=pass (1024-bit key; unprotected) header.d=yandex.ru header.i=@yandex.ru header.b="T3Ny1z5q"; dkim-atps=neutral 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 44XNCW3rd2z9sR9 for ; Mon, 1 Apr 2019 04:44:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; q=dns; s= default; b=Up/F6nPzziyGqzH3DFNGWKBK0Fx7Y8Xsz1LIj7wW+rPAXqeseJ5o5 LgT9AKqyCPJeqpXhwha1wH1oU3+5nz8efwXHWJjkOap4d/F4vZw26AQhc9Bso//V TaFn1ukVYOeOg/J8aqUW9w0eV1tJ3hceHtEFlQc4zWOmqGpsVmkp+0= 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:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; s=default; bh=7bPCbo21ZX5Tg7NXUDD1JXCMGjI=; b=dgp6wV/+VRrTrYcDsiw4pzfGDjp/ iicFO0ar42df4vZUvng/G7DkB2cZm04XZkh9jy84tjiQGhmfi1Jn6Hje+1ONxx3H 1jl7sOPtLKGsxhXgwLpa2zGfS5w6AFNSHPZYGasZSeyTbNF9wKwQyLFt1SLRzh4z ZCVO+d9tRVW4tzA= Received: (qmail 76996 invoked by alias); 31 Mar 2019 17:44:38 -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 76969 invoked by uid 89); 31 Mar 2019 17:44:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS, URIBL_BLOCKED autolearn=ham version=3.3.1 spammy=UD:ru, INTERNAL, HX-Languages-Length:4536, treating X-HELO: forward103o.mail.yandex.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1554054272; bh=kypWy06sc74+hztJzm/lWkZzp89PJo0AlbBFfAmNqtI=; h=In-Reply-To:Subject:To:From:References:Date:Message-Id; b=T3Ny1z5qgeT76neMM5s54NmSBq5qGrE7+1jJvSsI1OSCmMrBw2+SvQARhszXDRQHU MT2kVc8Y8MatmVxkgIi6jk20vcYnEXDDuodNoYUrA8QYADX6/Tbr9TgfgWr1L9EO8D Q+uZ/xw/wo6nNFSxAC0EyEqu/l3W8ifTcdd/nebw= Authentication-Results: mxback7g.mail.yandex.net; dkim=pass header.i=@yandex.ru From: Konstantin Kharlamov To: libc-alpha@sourceware.org Subject: [PATCH v2 2/3] nss/grp: don't pass src by value to copy_grp Date: Sun, 31 Mar 2019 20:44:19 +0300 Message-Id: <20190331174420.30823-3-Hi-Angel@yandex.ru> In-Reply-To: <20190331174420.30823-1-Hi-Angel@yandex.ru> References: <20190331174420.30823-1-Hi-Angel@yandex.ru> MIME-Version: 1.0 Fixes LGTM warning: "This parameter of type spwd is 72 bytes - consider passing a const pointer/reference instead." Signed-off-by: Konstantin Kharlamov --- grp/grp-merge.c | 24 ++++++++++++------------ grp/grp-merge.h | 2 +- nss/getXXbyYY_r.c | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/grp/grp-merge.c b/grp/grp-merge.c index 8227d52ea5..ad2c8cd5a5 100644 --- a/grp/grp-merge.c +++ b/grp/grp-merge.c @@ -36,7 +36,7 @@ }) int -__copy_grp (const struct group srcgrp, const size_t buflen, +__copy_grp (const struct group *srcgrp, const size_t buflen, struct group *destgrp, char *destbuf, char **endptr) { size_t i; @@ -46,24 +46,24 @@ __copy_grp (const struct group srcgrp, const size_t buflen, char **members = NULL; /* Copy the GID. */ - destgrp->gr_gid = srcgrp.gr_gid; + destgrp->gr_gid = srcgrp->gr_gid; /* Copy the name. */ - len = strlen (srcgrp.gr_name) + 1; + len = strlen (srcgrp->gr_name) + 1; BUFCHECK (len); - memcpy (&destbuf[c], srcgrp.gr_name, len); + memcpy (&destbuf[c], srcgrp->gr_name, len); destgrp->gr_name = &destbuf[c]; c += len; /* Copy the password. */ - len = strlen (srcgrp.gr_passwd) + 1; + len = strlen (srcgrp->gr_passwd) + 1; BUFCHECK (len); - memcpy (&destbuf[c], srcgrp.gr_passwd, len); + memcpy (&destbuf[c], srcgrp->gr_passwd, len); destgrp->gr_passwd = &destbuf[c]; c += len; /* Count all of the members. */ - for (memcount = 0; srcgrp.gr_mem[memcount]; memcount++) + for (memcount = 0; srcgrp->gr_mem[memcount]; memcount++) ; /* Allocate a temporary holding area for the pointers to the member @@ -74,11 +74,11 @@ __copy_grp (const struct group srcgrp, const size_t buflen, /* Copy all of the group members to destbuf and add a pointer to each of them into the 'members' array. */ - for (i = 0; srcgrp.gr_mem[i]; i++) + for (i = 0; srcgrp->gr_mem[i]; i++) { - len = strlen (srcgrp.gr_mem[i]) + 1; + len = strlen (srcgrp->gr_mem[i]) + 1; BUFCHECK (len); - memcpy (&destbuf[c], srcgrp.gr_mem[i], len); + memcpy (&destbuf[c], srcgrp->gr_mem[i], len); members[i] = &destbuf[c]; c += len; } @@ -131,7 +131,7 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend, treating the new lookup as NSS_STATUS_NOTFOUND). */ if (mergegrp->gr_gid != savedgrp->gr_gid || strcmp (mergegrp->gr_name, savedgrp->gr_name)) - return __copy_grp (*savedgrp, buflen, mergegrp, mergebuf, NULL); + return __copy_grp (savedgrp, buflen, mergegrp, mergebuf, NULL); /* Get the count of group members from the last sizeof (size_t) bytes in the mergegrp buffer. */ @@ -195,6 +195,6 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend, /* Finally, copy the results back into mergebuf, since that's the buffer that we were provided by the caller. */ - return __copy_grp (*savedgrp, buflen, mergegrp, mergebuf, NULL); + return __copy_grp (savedgrp, buflen, mergegrp, mergebuf, NULL); } libc_hidden_def (__merge_grp) diff --git a/grp/grp-merge.h b/grp/grp-merge.h index d483ea2bf1..46dcdae5de 100644 --- a/grp/grp-merge.h +++ b/grp/grp-merge.h @@ -24,7 +24,7 @@ /* Duplicate a grp struct (and its members). When no longer needed, the calling function must free(newbuf). */ int -__copy_grp (const struct group srcgrp, const size_t buflen, +__copy_grp (const struct group *srcgrp, const size_t buflen, struct group *destgrp, char *destbuf, char **endptr); /* Merge the member lists of two grp structs together. */ diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c index cf867210fc..4b8d5e6d08 100644 --- a/nss/getXXbyYY_r.c +++ b/nss/getXXbyYY_r.c @@ -131,7 +131,7 @@ /* Set defaults for merge functions that haven't been defined. */ #ifndef DEEPCOPY_FN static inline int -__copy_einval (LOOKUP_TYPE a, +__copy_einval (const LOOKUP_TYPE *a, const size_t b, LOOKUP_TYPE *c, char *d, @@ -351,7 +351,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, acquired values. * If the next action is MERGE, then it will be added to the buffer saved from the previous source. */ - err = DEEPCOPY_FN (mergegrp, buflen, resbuf, buffer, NULL); + err = DEEPCOPY_FN (&mergegrp, buflen, resbuf, buffer, NULL); CHECK_MERGE (err, status); status = NSS_STATUS_SUCCESS; } @@ -377,7 +377,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, } } - err = DEEPCOPY_FN (*resbuf, buflen, &mergegrp, mergebuf, &endptr); + err = DEEPCOPY_FN (resbuf, buflen, &mergegrp, mergebuf, &endptr); CHECK_MERGE (err, status); do_merge = 1; }