Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8914105ybi; Tue, 23 Jul 2019 17:59:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTenh5iT044GOtEt0/HHdV2/gSNxFXNuABI/BbO9TI0femqzFfG6fmlfrOJDqPs/R1Jh3o X-Received: by 2002:a17:90a:9301:: with SMTP id p1mr84770166pjo.22.1563929989595; Tue, 23 Jul 2019 17:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563929989; cv=none; d=google.com; s=arc-20160816; b=NfapWUDr1QAHetmVxgu8qpLKiYLF4+yC0Y/VtROs0D3NtwQ4rU1KY6bQIpcmtfpMmQ rARb+GBqABuB/EyYJC30aM2B+OxoF3CT7czslWVo4AHkrc8IKPwfSKgeEkk2cLqcxyex /Ts3u0noNvhp4BNXX0PYN1dJdDkJJu/VCPcvEOTRXn90Y/MH0fMMVtLat012nrt0cuM1 0ULGPOPMG/bvUGG9TvJzZVD4i1gvpkXz2Cyak7Bhbho+rPeYdIu9CHnRe3Qukna6/Le4 TMoPEj7kMB0rFfRb2QxY+6eJq31xHtA5KiXuMSyNGCSFn/sG11rCqmhUID1Bmxrbt5Lm UHEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=bYMW0agoA6NAMNNFJyrA3TRSs4/yqbH3bMHFPNKUcLs=; b=YzZRfMDPv4lYuC6oiJ72SV832/3+Xk/2fp7L+I2g3HbgCUbm7Fr6jsmsTzUbgrOH9x w6/+wi9CaTwlCi1U9ajsVj6qiaVpHpbpAdJRQunG8UQEmywBHLiz5+/MtQLcAFvQDOwN yhZ773f2MqwR8dBUlZORlf8wZ3ff1YoMy5xcKqJbkVfU0dUFON7HLteQsr5jVCbHyShG ZjfONyEHsdQM7hxPwnL/MsX3Jmuq1TVQ8+aybiRnVbwSlKtIJVuFSiTaILTCZ98MjZeu d46kUrspw9ful5uWmjN9PjRXS6dL7IN2dXgad+FrSdrgAv+hf1zxae6KIuY/S7NOkn1x daXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si13610868plk.364.2019.07.23.17.59.33; Tue, 23 Jul 2019 17:59:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732116AbfGWPuq (ORCPT + 99 others); Tue, 23 Jul 2019 11:50:46 -0400 Received: from smtprelay0123.hostedemail.com ([216.40.44.123]:37570 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731114AbfGWPup (ORCPT ); Tue, 23 Jul 2019 11:50:45 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 64E1F180A8134; Tue, 23 Jul 2019 15:50:44 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:355:379:599:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3873:3874:4321:5007:7576:7875:8603:10004:10400:10848:11232:11658:11914:12048:12297:12740:12760:12895:13069:13311:13357:13439:14659:21080:21451:21627:30012:30034:30054:30070:30079:30090:30091,0,RBL:23.242.196.136:@perches.com:.lbl8.mailshell.net-62.8.0.180 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:38,LUA_SUMMARY:none X-HE-Tag: jewel94_62725d90e75d X-Filterd-Recvd-Size: 2781 Received: from XPS-9350.home (cpe-23-242-196-136.socal.res.rr.com [23.242.196.136]) (Authenticated sender: joe@perches.com) by omf18.hostedemail.com (Postfix) with ESMTPA; Tue, 23 Jul 2019 15:50:42 +0000 (UTC) Message-ID: Subject: Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms From: Joe Perches To: David Laight , 'Rasmus Villemoes' , Linus Torvalds , "linux-kernel@vger.kernel.org" , Chris Metcalf Cc: Jonathan Corbet , Stephen Kitt , Kees Cook , Nitin Gote , "jannh@google.com" , "kernel-hardening@lists.openwall.com" , Andrew Morton Date: Tue, 23 Jul 2019 08:50:40 -0700 In-Reply-To: <5ffdbf4f87054b47a2daf23a6afabecf@AcuMS.aculab.com> References: <7ab8957eaf9b0931a59eff6e2bd8c5169f2f6c41.1563841972.git.joe@perches.com> <5ffdbf4f87054b47a2daf23a6afabecf@AcuMS.aculab.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.5-0ubuntu0.18.10.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (adding Chris Metcalf) On Tue, 2019-07-23 at 15:41 +0000, David Laight wrote: > From: Rasmus Villemoes > > Sent: 23 July 2019 07:56 > ... > > > +/** > > > + * stracpy - Copy a C-string into an array of char > > > + * @to: Where to copy the string, must be an array of char and not a pointer > > > + * @from: String to copy, may be a pointer or const char array > > > + * > > > + * Helper for strscpy. > > > + * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination. > > > + * > > > + * Returns: > > > + * * The number of characters copied (not including the trailing %NUL) > > > + * * -E2BIG if @to is a zero size array. > > > > Well, yes, but more importantly and generally: -E2BIG if the copy > > including %NUL didn't fit. [The zero size array thing could be made into > > a build bug for these stra* variants if one thinks that might actually > > occur in real code.] > > Probably better is to return the size of the destination if the copy didn't fit > (zero if the buffer is zero length). > This allows code to do repeated: > offset += str*cpy(buf + offset, src, sizeof buf - offset); > and do a final check for overflow after all the copies. > > The same is true for a snprintf()like function Chris? You added this function. Do you have an opinion here?