Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5780477rwb; Mon, 5 Dec 2022 04:08:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf5XocNUH4iPdePtel1ZDqXNg6UiHpuq7krWUmOsgttk41yNmPDsPhqWtHsq7oHRWWhYytBI X-Received: by 2002:a05:6402:1802:b0:461:72cb:e5d with SMTP id g2-20020a056402180200b0046172cb0e5dmr65215530edy.410.1670242134920; Mon, 05 Dec 2022 04:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670242134; cv=none; d=google.com; s=arc-20160816; b=QgS0kXJ+id7cjv5I3RzTMZT+HWqjVCM1jxSMBKb5nNqfgwNecSnRgY+Py9xPrwKubB LmKtGJLBblTPZJ8tXUVJbkOXkYXXQ1eZI9aen1jek348d7IAPZIO+5+2SNRm02mvKnS6 uERBFpUsHlUl9PfAOtW8YKW9ddX33p1VTCATn3tpsoStyVaoa0E51Gp4BEBcjFLIswQ0 lVD3iY9WZtYMe7fya7MLOWaBVJrV3BWs98n4Vv4fORX5o+yiT21lo73IZ/ENqqJg1jGr jirUaSDzF2Os2lZ4h5cLYS3mbPedl0LKK3Ms4EItrZoXuRGTWGqA9L1k0Hx8jIhIWQer WibQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=dY4G+OEJjaW8DNATpJYL13lbvz2Po4I+gGx8UGgRvzY=; b=ognheT6/5qEHUGt2ksuE1/jSojSh9UWapL3HeI/h6ygF38dh/JZb+t8p8AiSLdNRAf 6eFtcp0hyLBviVB5dcmMr5V7xGo9kxtGpEi1IAnphZF5LxzvFUJAggqhPujkthp+VGVj YLy602fRRWpCu5n4/wCMY/IEK5S85cFcR3nAbxwaeMSVGc4itdHtnJmR1wD0xa+nTvit bs+MIELrHRxfCc2FsMkuQfWBbIYpBomdfWpVB/Yj3w3LqzzQutiU68JdS4ySeF9stuj4 3sxnbgUpBQ72pw1/JxvGRm96FR8W/SF2llKVHF0CTnYLbYsrXA66JeLlE+xQymuvP61o I4Ew== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb9-20020a1709076d8900b007879bb73291si12172051ejc.807.2022.12.05.04.08.34; Mon, 05 Dec 2022 04:08:54 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbiLELih (ORCPT + 82 others); Mon, 5 Dec 2022 06:38:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbiLELiN (ORCPT ); Mon, 5 Dec 2022 06:38:13 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 514521A07E for ; Mon, 5 Dec 2022 03:38:05 -0800 (PST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NQhPS0bFsz8RSdJ; Mon, 5 Dec 2022 19:38:04 +0800 (CST) Received: from szxlzmapp03.zte.com.cn ([10.5.231.207]) by mse-fl2.zte.com.cn with SMTP id 2B5Bbxpw076280; Mon, 5 Dec 2022 19:37:59 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp02[null]) by mapi (Zmail) with MAPI id mid14; Mon, 5 Dec 2022 19:38:02 +0800 (CST) Date: Mon, 5 Dec 2022 19:38:02 +0800 (CST) X-Zmail-TransId: 2b04638dd81affffffffbefa11df X-Mailer: Zmail v1.0 Message-ID: <202212051938026789359@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , Subject: =?UTF-8?B?W1BBVENIIGxpbnV4LW5leHRdIHZpcnRpb19jb25zb2xlOiB1c2Ugc3Ryc2NweSB0byBpbnN0ZWFkIG9mIHN0cm5jcHkoKQ==?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl2.zte.com.cn 2B5Bbxpw076280 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 638DD81C.000 by FangMail milter! X-FangMail-Envelope: 1670240284/4NQhPS0bFsz8RSdJ/638DD81C.000/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 638DD81C.000/4NQhPS0bFsz8RSdJ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY 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 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/char/virtio_console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 6a821118d553..d5ac4d955bc8 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -1666,9 +1666,8 @@ static void handle_control_message(struct virtio_device *vdev, "Not enough space to store port name\n"); break; } - strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), - name_size - 1); - port->name[name_size - 1] = 0; + strscpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), + name_size); /* * Since we only have one sysfs attribute, 'name', -- 2.15.2