From patchwork Sun Mar 24 12:21: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: 1063129 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-100857-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="IQ0kQb3/"; dkim=pass (1024-bit key; unprotected) header.d=yandex.ru header.i=@yandex.ru header.b="AEBv0r1x"; 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 44RxNB6C0Jz9sRy for ; Sun, 24 Mar 2019 23:22:02 +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=PkhsIi183q79gmHCrD93vmAR0IaDAxmNh3+QtrS0sGAWwrGroRQ9C L+m8w7uA/TEnabuS25CIIBCTX6iPhW4K8mlIUM2zcEHsBVRdaDPh9Zh43k8CqCvk oJJ/W4w/UzX9FCvnQopssFlowgFzMSrxUxVn5sFFsZe+UMgy53YeVU= 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=IQ0kQb3/2CoKb8slv1MLfrdNsmzF 1IdQ1OgixBzij7AJzchn1Y0x3MpQUK8uy+Tt7+zso/U5NCzx4o8hkuiisCH7lHgZ Giz0mZcn/R2hEBPNNgquu26qD2iOcbf7dZ3ZVJv6Dku6KZ5eb16mdzVdu/BocOFA IsKLa8co7z5dczA= Received: (qmail 3956 invoked by alias); 24 Mar 2019 12:21:37 -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 3905 invoked by uid 89); 24 Mar 2019 12:21:36 -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 autolearn=ham version=3.3.1 spammy=defaults, Duplicate, HX-Languages-Length:4533, password X-HELO: forward102p.mail.yandex.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1553430092; bh=kypWy06sc74+hztJzm/lWkZzp89PJo0AlbBFfAmNqtI=; h=In-Reply-To:Subject:To:From:References:Date:Message-Id; b=AEBv0r1x4W9Ye0KXGnEy7kKO/dXGImxHIkYn28EM3KJeDN+3ka5qzrpTboPdMdg/l hi0O3EH+y8ryM+0uDI0KVqpGJ9q1zHAmIcQpbRQicds+ONkXUyQk06mndztoL37/WR FEAjn8ev1LfPzsnFhC8KealnQ9SLXciWARWgFafI= Authentication-Results: mxback21o.mail.yandex.net; dkim=pass header.i=@yandex.ru From: Konstantin Kharlamov To: libc-alpha@sourceware.org Subject: [PATCH 3/5] nss/grp: don't pass src by value to copy_grp Date: Sun, 24 Mar 2019 15:21:19 +0300 Message-Id: <20190324122121.6430-4-Hi-Angel@yandex.ru> In-Reply-To: <20190324122121.6430-1-Hi-Angel@yandex.ru> References: <20190324122121.6430-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; }