Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3654957rdg; Wed, 18 Oct 2023 01:53:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+Vafd/5brSoEkYtQ/QMKF2rD0tSJAUECJzObaV1a4BvQ+hQ6GXwFZG1/a5ls/Zj4KlB7p X-Received: by 2002:a17:90b:1108:b0:268:b0b:a084 with SMTP id gi8-20020a17090b110800b002680b0ba084mr4277696pjb.46.1697619202452; Wed, 18 Oct 2023 01:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697619202; cv=none; d=google.com; s=arc-20160816; b=zBG1/ixh3J4AqNjVM+9wOVaYbfbR4IXBIOtSjTA+HLXlmNJ1sDOOxhRZra8TodQm4G 6ijvAeyBsiezbDQ3porxnSTW3T0qjgEkVVSZcVLU7lpHNrLRPKoa8lf1e45nttO5U1NC 6EVKD5/5EWo1+tkdNq2hxnh74Kwmy7IZFqE7ITxt+QxZe8NMNv9vw5AMp+QHnrBs9Sb1 mSj/s5r274ezba5g5rG2vktt2EnPSe+y4WvxEPLSmfsHJLvDgAp7hJnFlDbV4vrWlMdn 3O91XISsNtOSmK4v4D7b13ptc9VDCsuZoy55RPVZMbJRVUSp9TqCt9AAQBrXcr9UY2y3 J+NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=geUEpwvi3+e4pwlZJkv1VdkNb71jcT4N9IHDjoo0hiw=; fh=I3IM077lDFh7+13t0jYEaipevAkPvMJDOvJJbuII80c=; b=IWANeSB354gOiYUJ1LV0IqiMh9b201oSHsnP23BsDE5VtsOWLo0lUKY8ub6qXux3Dl H0JwhwdOjYhx0xnU3PzPhZMf3G1P5ANLy8GJv/boXvvMKbK+BDNCLoGOftzgLXttTtPz pKZm77UPkGS1tTx7N17gx8LitGEnbQ+kcBhCK0N2r9t7zyNdNsmcF3BZfBl/1/lsj7wN RooM6g9EIPqn6a8RGf+DREkQrDMc9EfKWMIRUGne9KExiKbSZsgq+WqupUaczQ4uDrQi 3ai0AtLSPbeViwa7MFXHsMBvZnRWHb/zIwFkMHkWgO2CnaMTq1+drm4p+GiblFyyfrOd rFNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LpTtpeXf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id m4-20020a633f04000000b00563da455862si693027pga.311.2023.10.18.01.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 01:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LpTtpeXf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 1C47980B9082; Wed, 18 Oct 2023 01:53:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbjJRIxI (ORCPT + 99 others); Wed, 18 Oct 2023 04:53:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjJRIxG (ORCPT ); Wed, 18 Oct 2023 04:53:06 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2737F9D for ; Wed, 18 Oct 2023 01:53:05 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4065f29e933so67352195e9.1 for ; Wed, 18 Oct 2023 01:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697619183; x=1698223983; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=geUEpwvi3+e4pwlZJkv1VdkNb71jcT4N9IHDjoo0hiw=; b=LpTtpeXfJ4aTxvCgA6cigOFUsrZ3dtvHPA/wKi9D0daNfVJ01m1veIuAFD72oRwifM 4jBtV2jw9pi2nOBOVDuB91c+k54Mukx8VB2VyVJ4EMfy0pgem2cCbovQBJm9M2dhkifQ sBTOcbCZkbfIszxS2KlG4q9B5DiXHl2qfCHbY0T4HfCAPliF2mWs7Xx60bxy1H27u8aU jUU76WzqwoMX0D6m05upZOk6o2M6jIDuR1GO5fc9uWfvugpr3GDnclragkGzjIdDL+0s bEucDYBvDStWMgB7pJpUjQPv4ItbMSBlFJoZU/uu9Jjq4/D0WI9cekvvL4vCgHN1fEzk GLJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697619183; x=1698223983; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=geUEpwvi3+e4pwlZJkv1VdkNb71jcT4N9IHDjoo0hiw=; b=W1fu/+hl87UuiJ9vqIcuo0dXW+VjjxA9cJPCdr0ASTV0JFGgiZMO8RoHHEwicm78yU +21hWsCI8Occ+h3chEV3fQQ/G3G9UI5ZRLX0YdrAzhxj+VH3Y9nDo68+4HD+wM5CpO0e gMjc8Kge5mYDyNgxWqFI+JLtHBv8FUJ8JZL03taqhugblmAyJBnp1kgFkpzW9KGA1K3v J7LKU+rRfpMD/LN6w/xKGaGyI8hZU10hyVYcXXgscrUBCkYLzEqKpoKwfK07a+orpOqM /PRj8PjGqOCZwKMQz2ECM/rVpkis42pVCSDs23KUb3NUAEJI8WnKa/XzztLciA4+DqaZ ANfw== X-Gm-Message-State: AOJu0YztXnjJt8VbyBbiof0fXZDuZhalyF++wTYY0B2xh2OKJrK225e1 gHvow8PUYl3VVpVu6QRGUCk= X-Received: by 2002:a5d:540d:0:b0:32d:9d99:d0a5 with SMTP id g13-20020a5d540d000000b0032d9d99d0a5mr3493755wrv.5.1697619183280; Wed, 18 Oct 2023 01:53:03 -0700 (PDT) Received: from lab-ubuntu ([41.90.71.30]) by smtp.gmail.com with ESMTPSA id r12-20020adfce8c000000b0032d9caeab0fsm1612082wrn.77.2023.10.18.01.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 01:53:02 -0700 (PDT) Date: Wed, 18 Oct 2023 11:53:00 +0300 From: Calvince Otieno To: gustavo@embeddedor.com, outreachy@lists.linux.dev Cc: Greg Kroah-Hartman , Martyn Welch , Manohar Vanga , Calvince Otieno , linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev, Julia Lawall Subject: [PATCH V2] staging: vme_user: replace strcpy with strscpy Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 01:53:20 -0700 (PDT) Checkpatch suggests using strscpy() instead of strcpy(). The advantages of strscpy() are that it always adds a NUL terminator and prevents read overflows if the source string is not properly terminated. One potential disadvantage is that it doesn't zero pad the string like strcpy() does. In this specific context, both strscpy and strcpy performs the same operation without any functional difference. The reason for this equivalence is that the driver_name string "vme_fake" is shorter than the size of the fake_bridge->name array which is defined as 16 characters (struct vme_bridge {char name[VMENAMSIZ];...}). Thus, there is no risk of buffer overflow in either case. VMENAMSIZ variable holds a constant value of 16 (#define VMENAMSIZ 16) The null-terminated "vme_fake" string (static const char driver_name[] = "vme_fake";) can be safely copied into fake_bridge->name using either strscpy or strcpy. While using strscpy() does not address any bugs, it is considered a better practice and aligns with checkpatch recommendations. Signed-off-by: Calvince Otieno --- Changes in V2: - Make the commit message more clearer. - Remove the incident extra line change. drivers/staging/vme_user/vme_fake.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/vme_user/vme_fake.c b/drivers/staging/vme_user/vme_fake.c index 0e02c194298d..8ab5b43c70a6 100644 --- a/drivers/staging/vme_user/vme_fake.c +++ b/drivers/staging/vme_user/vme_fake.c @@ -1091,7 +1091,7 @@ static int __init fake_init(void) tasklet_init(&fake_device->int_tasklet, fake_VIRQ_tasklet, (unsigned long)fake_bridge); - strcpy(fake_bridge->name, driver_name); + strscpy(fake_bridge->name, driver_name, sizeof(fake_bridge->name)) /* Add master windows to list */ INIT_LIST_HEAD(&fake_bridge->master_resources); -- 2.34.1