From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 484A4C4320A for ; Wed, 11 Aug 2021 07:40:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E2DF60FC0 for ; Wed, 11 Aug 2021 07:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235740AbhHKHlE (ORCPT ); Wed, 11 Aug 2021 03:41:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:54276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234043AbhHKHlC (ORCPT ); Wed, 11 Aug 2021 03:41:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4BEBC6056B; Wed, 11 Aug 2021 07:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628667639; bh=rdqhOz0L1PAh4KXTeSKY4XD8/H+gEn5LQTTMro2BQ9M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uQVzxGtxi3P/hMjDt7J/0kB2xhblAqToa9zpLvlF8G+Vf83bZyGVBqazQX+UNuqL7 0Nr4/5GeWK2BB6TfyNUG48RN6NEs/twP/NVKGi+wdis36tHP64IE6qNW4WZJxdhRF7 QX+oYwtXG362ZK/Rh5crKTcuFKcObaKlFP3l5lwE+f49eN7wJsLEFzl1ZzoBrQAb9Y CjoyTSylavwgQXDExA4IJY79Lr3nElg5YusevfuvinucbLmlLyiiD2VmzaeCtt+uDi OEQjQ+66vfF0aFHvX8fEAYLiFEdbavEvLltA6xGTpiwuZ2Yfmxti884966gk3bANhO 1evdzfauj/Xjw== Date: Wed, 11 Aug 2021 09:40:34 +0200 From: Robert Richter To: Joe Perches Cc: Len Baker , Borislav Petkov , Mauro Carvalho Chehab , Tony Luck , James Morse , Kees Cook , linux-hardening@vger.kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] drivers/edac/edac_mc: Remove all strcpy() uses Message-ID: References: <20210807155957.10069-1-len.baker@gmx.com> <20210808112617.GA1927@titan> <99448ef29830fda9b19409bc23b0e7513b22f7b7.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10.08.21 08:02:17, Joe Perches wrote: > On Tue, 2021-08-10 at 16:36 +0200, Robert Richter wrote: > > On 09.08.21 10:18:58, Joe Perches wrote: > > > > > strscpy and scnprintf have different return values and it's simpler > > > and much more common to use scnprintf for appended strings that are > > > limited to a specific buffer length. > > > > Calculating the bytes written from the return value is a oneliner. > > Not really. > You still have to test for strscpy's possible return of -E2BIG. I thought of: num = strscpy(p, OTHER_LABEL, len); num = num < 0 ? len : num; len -= num; p += num; Clearly, this does not look nice, esp. if this is repeated in the code. That's why I prefer the strlen(p) implementation: strscpy(p, OTHER_LABEL, len); len -= strlen(p); p += strlen(p); -Robert