Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3293144rwb; Sat, 3 Dec 2022 02:27:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6hq88fXrmFiWsqYfTU5KVixJ+gRsjuHmzhs7hJWaJYgbaUICzgerQE/S2CFGO66c4kzmHv X-Received: by 2002:a63:cd09:0:b0:476:d44d:355 with SMTP id i9-20020a63cd09000000b00476d44d0355mr48301820pgg.289.1670063231693; Sat, 03 Dec 2022 02:27:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670063231; cv=none; d=google.com; s=arc-20160816; b=dpqPaBTYIftqgEPHzV9YeiiV593YduQm8adayoglf32nbXhtqDscYdvIPJh4d7q5vr RFnmLJlX0+STxdoSkzKEWQWMZHB8EM0tXcxP8Dh7ZDbCuQHfGKvwch9bicufX7uSsuZU 6Br/hL59rovL5VmNS5OhUXj/5TNwBRD/JFf3+Y6gkcCJ2uvD6GHIyGRsdHruXfhzQVHh X/lzkII/pYyIBqRn/0Fa6hShwawNY8LMcSKoVhW8/jBeewupT59z4UNjy9IcektlhuIg AMfO/3IU3QRnxvi/pjekuw2YVuPTJgFmJVgEdOpbdBdPbK6QYCl+jY8Icjgkawn1r4za Pyog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date; bh=+EkLNcrhQmV6ScghXvyEVU3z6UcRLq41FVV1cZ2WQkc=; b=WlMUkMBymp6qmEXKspUkpVG0fi0GjfApOsN1gtMFHqNV/RUe0zk8jTKeF5egw2dBVX vmyDDG9JsjAr7qGJ3YutqSDhRSWhe5a+myk8kKdSplE/U3RRLT1dnHTgtzDsceTOeHCD naNF6O5AEVEg3GSCaPaa+1lTi+PCyuSgJYWOhjMmkn9tafAX4oeSd3mayUM+d2w7EREE 14OFajSg3vtYN1TXjKcJUzdoaz0eTiDUks2w6V66doRhzgDY8cV9CG+ICgoo/S8KM15j p2VxYZVp0PevSNtT5ID7DAzwLclU5eGf4IPm17VZ7o+8SymbzHBGUpJ1088FIRTieS3l Y0/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a635645000000b0046e96b9ecfdsi9341201pgm.801.2022.12.03.02.27.00; Sat, 03 Dec 2022 02:27:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229513AbiLCJ4u (ORCPT + 83 others); 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) X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 >