Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp524846rdg; Thu, 12 Oct 2023 12:28:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUGrsAQqbvB23NeKQ07l1ut5j4M964LSCCeeArt7EJRwN/+ZEXp5aGK2CKrYESJ5/4mBRd X-Received: by 2002:a05:6870:10d7:b0:1e9:c2bd:f2e8 with SMTP id 23-20020a05687010d700b001e9c2bdf2e8mr2231647oar.23.1697138925641; Thu, 12 Oct 2023 12:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697138925; cv=none; d=google.com; s=arc-20160816; b=GPihq2PH3oxSY2lo/seGeqma7gaYQeIAngSCntNk6diCUeGG7dmSKz/UOxvIxX1PMe izWSWYTAK27y/GpSi8Ngy8PGaUkCNLSw845RUoX/HBEGNFa4xHkR5L/lC8lvF5IJIyav HBe3Npcobeu/LxKg5Tu1NAe8Ik5XahNG64O6ULt0o1k/nThljI0nzikM3lixf+oMJYz7 Ca6D5fWSM1+feED82v/YGsH5Qrgb3Zlg6qVxBsfZPe3If6XnR3zGZ9kTNwBMeS6zxOQo LQxRjfCZv9BsfPUDSd3oNuxQeiYYtOjDhW5f6OqiuuD4RjpOPXyVt6MLUn51PrpGCxO3 VwhA== 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=S9gOrgWsv2J6btDunJZLLHwFNG8Aa1HIXtQ4lvtTYx8=; fh=mGyJhLoyes5UYmi880x57YUcnckP5LrNU8NQ8p5ctgE=; b=uA+piNdAgj/GWQgnIJH6lNrjAtKJGQuemt4beHKlO4ICDW+VGpjW5gr9pwf5Dh+YC7 PdLM70jdPBHJMeerLKHc7UXUhNlacQXc3zDzalFQZ0LO50RRWr6TtItK73EIOxi8TvaM F6kP4EWZtC27TWigTMU9ke1IuIj+yVYQqadwJmxisVfw73fTAzFIAgHXoiYz6BXelOko YZTd5RmoVzzXBz/TuRo+gYuKEsHremQunMff9lwqiLV8CZ1IyWBS3RTAqAquTCVWxyVU hYtlTKXYMGB1145lfpxx3P2+GOJAjEtCXK0FrNB7uHTU3ySN6Na3lGcHSudsxv1EAvTU kteg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FayJEcrd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k64-20020a638443000000b00565e92e8734si93941pgd.769.2023.10.12.12.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:28:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FayJEcrd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id AC8628239B9E; Thu, 12 Oct 2023 12:28:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442093AbjJLT2m (ORCPT + 99 others); Thu, 12 Oct 2023 15:28:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441868AbjJLT2l (ORCPT ); Thu, 12 Oct 2023 15:28:41 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2049B7 for ; Thu, 12 Oct 2023 12:28:39 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5041bb9ce51so1761644e87.1 for ; Thu, 12 Oct 2023 12:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697138916; x=1697743716; 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=S9gOrgWsv2J6btDunJZLLHwFNG8Aa1HIXtQ4lvtTYx8=; b=FayJEcrd8I116WZ+WFFcwwY2DH+8IA2As7yLMYjf7TaQzuYfmtP2jEkFA4Dmgz/sg3 ZsYF5jyrfqLvqDH/KRfkUC6PTk1xgZcE1p2tD81+Lu1tzovOShOeQMFS85AhK3HlEdh/ VqahK6U2eJWD40Ibixvr77F5wcwXmaLdnxVgJporge5M+Et3GEXX4ggwS1wZI9H4B1ed R34KU/Ul1eSjecADdZ6hnPJXD0s0Bonb5F+QAtBTquD415GhcB0GUBDxy2sYduMqEh3X L4KZ1NA7+z8oivDYDRwgWhzgW5nXgWWn/xes2dqIcuK5GkczHi+R9oVKrR2qbJHsACam 6eLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697138916; x=1697743716; 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=S9gOrgWsv2J6btDunJZLLHwFNG8Aa1HIXtQ4lvtTYx8=; b=d74AoXvk4sKRwGBx1Oc+x5bqD48fSpZ02NVPn2bX/B9dmZk+8qLcxn3Ddl2kLUBc9T NNpKGBUnCWLmWetX/Cyb3HNIuvOCmCJbPBRVNAnm/KuGkk9rulKiI8v0o5F1BIvSchsK 64lunOgoRs/Ar23BIbgAafx9p03q6SpK8U9hGO9/ckJWkkWwL/7e+pxtghZSzVdSX8sn pemlfsy0DrvlRYIEHHj07MZOhezlEbABY9hAGQdJwXaw5gG5sVQfrHFK5IgZnAsmqXKG r49POOHLZvqPjnmuxEKIGDsAy5c4LjOZn+htavGD28hIua/MpsVv/thaqUE2P37GJWW1 aNDw== X-Gm-Message-State: AOJu0YwJ8dS/S8jD14ylPuQl9mTpHJwZ0yfzwFFYxtDhzUaU1hHWgw5w nAadIrpk/zaHuQhTezR4T3OzDh7etERwXQlD X-Received: by 2002:a19:4355:0:b0:505:7014:8c6b with SMTP id m21-20020a194355000000b0050570148c6bmr18569313lfj.50.1697138916275; Thu, 12 Oct 2023 12:28:36 -0700 (PDT) Received: from lab-ubuntu ([41.90.69.21]) by smtp.gmail.com with ESMTPSA id t27-20020a1709063e5b00b009a168ab6ee2sm11380536eji.164.2023.10.12.12.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:28:35 -0700 (PDT) Date: Thu, 12 Oct 2023 22:28:33 +0300 From: Calvince Otieno To: outreachy@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Archana , Dan Carpenter , Calvince Otieno , Bagas Sanjaya , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3] staging: wlan-ng: remove strncpy() use in favor of strscpy() Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:28:44 -0700 (PDT) In response to the suggestion by Dan Carpenter on the initial patch, this patch provides a correct usage of the strscpy() in place of the current strncpy() implementation. strscpy() copies characters from the source buffer to the destination buffer until one of the following conditions is met: - null-terminator ('\0') is encountered in the source string. - specified maximum length of the destination buffer is reached. - source buffer is exhausted. Example: char dest[11]; const char *PRISM2_USB_FWFILE = "prism2_ru.fw"; strscpy(dest, PRISM2_USB_FWFILE, sizeof(dest)); In this case, strscpy copies the first 10 characters of src into dest and add a null-terminator. dest will then contain "prism2_ru.f" with proper null-termination. Since the specified length of the dest buffer is not derived from the dest buffer itself and rather form plug length (s3plug[i].len), replacing strcpy() with strscpy() is a better option because it will ensures that the destination string is always properly terminated. Signed-off-by: Calvince Otieno --- Patch version v3: Correct the patch subject headline. staging: wlan-ng: remove strncpy() use in favor of strscpy() Patch version v2 : Correct implementation of the strscpy() drivers/staging/wlan-ng/prism2fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/wlan-ng/prism2fw.c b/drivers/staging/wlan-ng/prism2fw.c index 5d03b2b9aab4..3ccd11041646 100644 --- a/drivers/staging/wlan-ng/prism2fw.c +++ b/drivers/staging/wlan-ng/prism2fw.c @@ -725,7 +725,7 @@ static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks, if (j == -1) { /* plug the filename */ memset(dest, 0, s3plug[i].len); - strncpy(dest, PRISM2_USB_FWFILE, s3plug[i].len - 1); + strscpy(dest, PRISM2_USB_FWFILE, s3plug[i].len); } else { /* plug a PDR */ memcpy(dest, &pda->rec[j]->data, s3plug[i].len); } Patch version v1: Replacing strncpy() with strscpy() drivers/staging/wlan-ng/prism2fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/wlan-ng/prism2fw.c b/drivers/staging/wlan-ng/prism2fw.c index 5d03b2b9aab4..57a99dd12143 100644 --- a/drivers/staging/wlan-ng/prism2fw.c +++ b/drivers/staging/wlan-ng/prism2fw.c @@ -725,7 +725,7 @@ static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks, if (j == -1) { /* plug the filename */ memset(dest, 0, s3plug[i].len); - strncpy(dest, PRISM2_USB_FWFILE, s3plug[i].len - 1); + strscpy(dest, PRISM2_USB_FWFILE, s3plug[i].len - 1); } else { /* plug a PDR */ memcpy(dest, &pda->rec[j]->data, s3plug[i].len); } -- Calvince Otieno