Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1096446pxt; Sat, 7 Aug 2021 00:24:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhiCTGc0qMtrOsCbzh9RuzojoGtDSLAcnmdZL6d++3O1DkXt8a1Fc8PNYtx2Gr06lQKLXd X-Received: by 2002:a02:a40f:: with SMTP id c15mr13767739jal.38.1628321048373; Sat, 07 Aug 2021 00:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628321048; cv=none; d=google.com; s=arc-20160816; b=BhQgH6PKVSsghLwkLkMn68Tshi++UHUSkmmg7uqjHAUeQKbl3LOjnTFIPpiDKJY7Px o5G6pF5xWJ58mj4HWrShceb0ZMuxVd+MfJj2noRPQ4e2jV2Si4bYdSH6nExjJPk6GyBd 0lwro0Wt+MYF0uhQcv7sCblyHIePVGJA5IY95vh3wrthuS9yPl2yoFM1bvBQ+5coTHVK VN8rb7BEiurYSkcQhPIW1POqzDiACDXRwjj4IOX+8jwJ8qjSqAkSCNGLBG+mdQ09mNXW UGH9GwfA+dKSAMQTHPVqZ7QXiMQJVcifp2G6odfQGeQd6Cp72FJ3Q9EZoS2CqDTj4Ziq bJwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=Yjro650uky+q7xi4IJNspMxBEhv+H7/jBVD/E2vRXOA=; b=xcokT2i2LPYH9vrFxIX8lCz5l08jpXFvq9hDMnJ2XD+AFSLMMYr3uulNHVa8d35ZMe Klysp2IWEO25GjxUog8PDecFvbdKhetJjXYXd97Ri9bblTp11DeouL3sF4tyHrrMQ6xt BIxDvol7kfnUoFYkMB14BazfcfKrg5GnTws5CqZUVQ2b0lE2wWJtHRyblQkJiVDllpZU zBm3+Fv3PFZ4XWo2JKL5Q1GMMXRx8UbDRkih8LJ4GcYhEiZs2V9zEwtxnqn+iJTArv7G VkcxSu0IhnMqXYiueQ5toK5TXP2yBetHmPSpsTdFr0vuvJob4mxq0dVS3P8sOPLeFAQO /p0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si3839546jao.99.2021.08.07.00.23.55; Sat, 07 Aug 2021 00:24:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231405AbhHGHXb (ORCPT + 99 others); Sat, 7 Aug 2021 03:23:31 -0400 Received: from smtpbg127.qq.com ([109.244.180.96]:43394 "EHLO smtpbg.qq.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231317AbhHGHXa (ORCPT ); Sat, 7 Aug 2021 03:23:30 -0400 X-QQ-mid: bizesmtp46t1628320958tjmcxxi0 Received: from localhost.localdomain (unknown [125.69.42.194]) by esmtp6.qq.com (ESMTP) with id ; Sat, 07 Aug 2021 15:22:36 +0800 (CST) X-QQ-SSF: 01000000002000B0C000B00A0000000 X-QQ-FEAT: Cjrn31CahfWgDw7UMKXdHlRwa6tXiaeZj606PdrsMAHJvFwTr0Ol7tAVgd2t8 8UQrp4Od/ZW3X5HNjCgZFyNBvEbu9AafqzaF99RZi+ml2VeAYkbD7ps6SEejQPt3ujh/POt DnmqPAWay4LJ405EYx/Q2B6R32YTkLL7cfXmULMmWM8k+mB7j5GX3BlgLNtX5bbFKUzhMRc LcOdf4GZqbUdeHMjDZdMUEVRN7ILm9Nuy84E6fQq9/iD4FT+SJa4Egus2qLMfxzwNHL0vb8 PaJSpLQmJw1g1FBgJpkg40ic34WVJ1QG+y81CR+1XCc/A3NkDtCUVVqsw5sEpF0MMJIdXOU aLLtFZw1qbGWCmoRNc= X-QQ-GoodBg: 0 From: Jason Wang To: mpe@ellerman.id.au Cc: benh@kernel.crashing.org, paulus@samba.org, christophe.leroy@csgroup.eu, wangborong@cdjrlc.com, wangkefeng.wang@huawei.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] powerpc: use strscpy to replace strlcpy Date: Sat, 7 Aug 2021 15:21:54 +0800 Message-Id: <20210807072154.64512-1-wangborong@cdjrlc.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:cdjrlc.com:qybgspam:qybgspam1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The strlcpy should not be used because it doesn't limit the source length. As linus says, it's a completely useless function if you can't implicitly trust the source string - but that is almost always why people think they should use it! All in all the BSD function will lead some potential bugs. But the strscpy doesn't require reading memory from the src string beyond the specified "count" bytes, and since the return value is easier to error-check than strlcpy()'s. In addition, the implementation is robust to the string changing out from underneath it, unlike the current strlcpy() implementation. Thus, We prefer using strscpy instead of strlcpy. Signed-off-by: Jason Wang --- arch/powerpc/platforms/powermac/bootx_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/powermac/bootx_init.c b/arch/powerpc/platforms/powermac/bootx_init.c index d20ef35e6d9d..741aa5b89e55 100644 --- a/arch/powerpc/platforms/powermac/bootx_init.c +++ b/arch/powerpc/platforms/powermac/bootx_init.c @@ -243,7 +243,7 @@ static void __init bootx_scan_dt_build_strings(unsigned long base, DBG(" detected display ! adding properties names !\n"); bootx_dt_add_string("linux,boot-display", mem_end); bootx_dt_add_string("linux,opened", mem_end); - strlcpy(bootx_disp_path, namep, sizeof(bootx_disp_path)); + strscpy(bootx_disp_path, namep, sizeof(bootx_disp_path)); } /* get and store all property names */ -- 2.32.0