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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EE95C7113B for ; Thu, 24 Aug 2023 21:59:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243724AbjHXV6w (ORCPT ); Thu, 24 Aug 2023 17:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238031AbjHXV6S (ORCPT ); Thu, 24 Aug 2023 17:58:18 -0400 Received: from sonata.ens-lyon.org (sonata.ens-lyon.org [140.77.166.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C3E172D; Thu, 24 Aug 2023 14:58:15 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id F1193200F3; Thu, 24 Aug 2023 23:58:07 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tJdgRRiDj2Ea; Thu, 24 Aug 2023 23:58:07 +0200 (CEST) Received: from begin.home (lfbn-bor-1-1163-184.w92-158.abo.wanadoo.fr [92.158.138.184]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 50228200F0; Thu, 24 Aug 2023 23:58:07 +0200 (CEST) Received: from samy by begin.home with local (Exim 4.96) (envelope-from ) id 1qZIL8-001mhZ-2z; Thu, 24 Aug 2023 23:58:06 +0200 Date: Thu, 24 Aug 2023 23:58:06 +0200 From: Samuel Thibault To: Justin Stitt Cc: William Hubbs , Chris Brannon , Kirk Reiser , speakup@linux-speakup.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] accessibility: speakup: refactor deprecated strncpy Message-ID: <20230824215806.3ulejc2gsapcl2mw@begin> Mail-Followup-To: Samuel Thibault , Justin Stitt , William Hubbs , Chris Brannon , Kirk Reiser , speakup@linux-speakup.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20230824-strncpy-drivers-accessibility-speakup-kobjects-c-v1-1-3a1ef1221e90@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230824-strncpy-drivers-accessibility-speakup-kobjects-c-v1-1-3a1ef1221e90@google.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Justin Stitt, le jeu. 24 août 2023 21:44:29 +0000, a ecrit: > `strncpy` is deprecated for use on NUL-terminated destination strings [1]. > > Use `strscpy` as it guarantees NUL-termination of its destination buffer [2] > which allows for simpler and less ambiguous code. > > Also, change `strlen(buf)` to `strlen(ptr)` to be consistent with > further usage within the scope of the function. Note that these are > equivalent: > |419 const char *ptr = buf; > > Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt Reviewed-by: Samuel Thibault > --- > Note: build-tested only. > --- > drivers/accessibility/speakup/kobjects.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/accessibility/speakup/kobjects.c b/drivers/accessibility/speakup/kobjects.c > index a7522d409802..8aa416c5f3fc 100644 > --- a/drivers/accessibility/speakup/kobjects.c > +++ b/drivers/accessibility/speakup/kobjects.c > @@ -422,12 +422,11 @@ static ssize_t synth_direct_store(struct kobject *kobj, > if (!synth) > return -EPERM; > > - len = strlen(buf); > + len = strlen(ptr); > spin_lock_irqsave(&speakup_info.spinlock, flags); > while (len > 0) { > bytes = min_t(size_t, len, 250); > - strncpy(tmp, ptr, bytes); > - tmp[bytes] = '\0'; > + strscpy(tmp, ptr, bytes); > string_unescape_any_inplace(tmp); > synth_printf("%s", tmp); > ptr += bytes; > > --- > base-commit: f9604036a3fb6149badf346994b46b03f9292db7 > change-id: 20230824-strncpy-drivers-accessibility-speakup-kobjects-c-4009e7df0936 > > Best regards, > -- > Justin Stitt >