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 DFA3FC4332F for ; Sat, 3 Dec 2022 09:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbiLCJ4u (ORCPT ); Sat, 3 Dec 2022 04:56:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiLCJ4s (ORCPT ); Sat, 3 Dec 2022 04:56:48 -0500 Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B84726D7CF for ; Sat, 3 Dec 2022 01:56:47 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 4D5F12012F; Sat, 3 Dec 2022 10:56:45 +0100 (CET) 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 9-wW9_7stpQY; Sat, 3 Dec 2022 10:56:45 +0100 (CET) Received: from begin (lfbn-bor-1-376-208.w109-215.abo.wanadoo.fr [109.215.91.208]) (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 925912010E; Sat, 3 Dec 2022 10:56:44 +0100 (CET) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1p1PGG-006rTz-0m; Sat, 03 Dec 2022 10:56:44 +0100 Date: Sat, 3 Dec 2022 10:56:44 +0100 From: Samuel Thibault To: yang.yang29@zte.com.cn Cc: w.d.hubbs@gmail.com, chris@the-brannons.com, kirk@reisers.ca, mushi.shar@gmail.com, speakup@linux-speakup.org, linux-kernel@vger.kernel.org, xu.panda@zte.com.cn Subject: Re: [PATCH linux-next] accessibility: speakup: use strscpy() to instead of strncpy() Message-ID: <20221203095644.6g7acpenj6brvjis@begin> Mail-Followup-To: Samuel Thibault , yang.yang29@zte.com.cn, w.d.hubbs@gmail.com, chris@the-brannons.com, kirk@reisers.ca, mushi.shar@gmail.com, speakup@linux-speakup.org, linux-kernel@vger.kernel.org, xu.panda@zte.com.cn References: <202212031421285953755@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202212031421285953755@zte.com.cn> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org yang.yang29@zte.com.cn, le sam. 03 déc. 2022 14:21:28 +0800, a ecrit: > From: Xu Panda > > The implementation of strscpy() is more robust and safer. > That's now the recommended way to copy NUL terminated strings. > > Signed-off-by: Xu Panda > Signed-off-by: Yang Yang > --- > drivers/accessibility/speakup/kobjects.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/accessibility/speakup/kobjects.c b/drivers/accessibility/speakup/kobjects.c > index a7522d409802..273c076b661a 100644 > --- a/drivers/accessibility/speakup/kobjects.c > +++ b/drivers/accessibility/speakup/kobjects.c > @@ -426,8 +426,7 @@ static ssize_t synth_direct_store(struct kobject *kobj, > 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); This needs to be bytes+1, otherwise the trailing `\0` will be put at bytes-1 instead of bytes as the original code does, thus eating one character. > string_unescape_any_inplace(tmp); > synth_printf("%s", tmp); > ptr += bytes; > -- > 2.15.2 >