Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp513342rdg; Thu, 12 Oct 2023 12:06:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGl21zjzXGZ/cLdY4UsRkZVlpot+OEUCgmxZZPbeRwy7NBmRCqzkNT3BrlSaR9tXwh1VPEF X-Received: by 2002:a05:6870:1358:b0:1e9:b4c0:2915 with SMTP id 24-20020a056870135800b001e9b4c02915mr2950330oac.55.1697137605488; Thu, 12 Oct 2023 12:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697137605; cv=none; d=google.com; s=arc-20160816; b=Hppiuoq271+1tWtj0o2jSLaml/240L1tUCn+VzAOP8VNyeAMDLK66q5W51Afs7Yh1b JtEHIPXA3uhCBSDIIjB6KAupedVz9r7O8V6AhjHJm7osQlyeKNFy7qD9BKZlefmvMPej J0m7zPt5hbDpBD4qdmOQwLLU44/B42JGGzZpCrQyKmCywKlRP/OAWbf8CucyLiDzyfGQ 3H8CZHEu99kIc+zq2/xgdo0VPkZFu9g0Rgjc3M7EEFT1hq2g8dukHR4pyAUrmuVxwhw+ DRrQs07rRb4YBRk7p9xZoUQ3yOt4wVmKUflkWhIr7KIJG8Qdj+A9EUdgWUi+X/LtpLVZ Yusw== 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=GRG/Q+khD2cAKTgkqi3DOUxaLzalQQAE2INM+FeGIZY=; fh=mGyJhLoyes5UYmi880x57YUcnckP5LrNU8NQ8p5ctgE=; b=hu6xjLJ3gDqKsSiFWL+Ld05mLN+Nd9S8bo0XgGr8FVwi7aDNVnjM2/CKaOkZ/uoMDO dDJ55xG/gWnVNW1n/yTmhtV4H3Nkx6w/DSeUx4duNPj3wwaUDofxwNqvOuaV++yjYvY7 72Zz/wuJucfDTfLEkTcpXH97XpVOdQJZGbxeyYEIqEtYKt/O4QDAe7C+2LOQDLkAM0sg 6h4TMs7h3UVXRKdD72jkXZrJ/d0rZCozpF8xF3S2rLHeTiTbVMM+wLdKFztzOnVrkoQ8 Dvzs3xwJMcDJRnCwsKpQ8dhGhJ2nsAMCQoU/tBUerjVn7KOtm7JqDIY8u1LEEMAhzn5R MctQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H1PyF7F5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id x5-20020a654145000000b00573f7d09445si2767801pgp.330.2023.10.12.12.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:06:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H1PyF7F5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 1C153825CD20; Thu, 12 Oct 2023 12:06:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441845AbjJLTG3 (ORCPT + 99 others); Thu, 12 Oct 2023 15:06:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjJLTG2 (ORCPT ); Thu, 12 Oct 2023 15:06:28 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA58D83 for ; Thu, 12 Oct 2023 12:06:26 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-50337b43ee6so1814134e87.3 for ; Thu, 12 Oct 2023 12:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697137584; x=1697742384; 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=GRG/Q+khD2cAKTgkqi3DOUxaLzalQQAE2INM+FeGIZY=; b=H1PyF7F57ErNf8MJVDuxzLGw3sW0x33XEcPaijVq9HD4kMjhT3NtJSgzJzByDfiYdR FJm8c8P+pkvv8XD+j8Vk9+DjgtlnSJuly/OY26VcJ6gB+bHDFTydYW4gDfRRZg1h26jP iLn/7MbnekPhLEVyBfw7BlgB0pAd+OFTewCj4ry/pNrdSVbVem+eafKL/o7EQg0ijvxA tUas2Toxlx5znVCK9ftvwrkS6Vx3Z2yYQNsVYeEzpIPnsHwa+IMWjsQUQogTrA/FTxyp 7MTnWZO7dZoeh1EJIESZUG2Jr1XMhON7EjDcV/RGVoJeZImKd+wFFPlFyR4xdWYwpi/N z64Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697137584; x=1697742384; 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=GRG/Q+khD2cAKTgkqi3DOUxaLzalQQAE2INM+FeGIZY=; b=KnCAoBSraF78KAOuxr8GZD1QeAbCDR+Biz3jPxhRACPT0hIONYgrrNi9971f/g82FQ KWXO+zG6Htregu3T5sA58yBwoH6ikYbm46WftJ57WtxGttfmNFmAWidYQ+kGRw32L7fJ Kg8WnsL2S9gamfIv4re1Fjd5VNzIHyONyHGg+RW3dtusWKTwyH4ekUYbteozhq+7Mha5 9swBIY3XWnHptRFkwcSCK2Oh4psKp0wZU6Wtsl3U3IP4Lyu35araQDovCelbOZBzCGv7 bvAY0WmK+BiA/WsaY5XImhTWUabPyMC/V3YGza8bl9M74/de/TMvnzUMpmtgOnrT64mF M/5w== X-Gm-Message-State: AOJu0YzMFxWl6NPAkVlhnosDqKeqCNtrkYFMX2dsqswj347PqvuaAI/Y P4yY33qljdbdE2sl1mfTRs+vHQvC1Wn6H4Uu X-Received: by 2002:ac2:560c:0:b0:507:9745:8629 with SMTP id v12-20020ac2560c000000b0050797458629mr873868lfd.55.1697137584259; Thu, 12 Oct 2023 12:06:24 -0700 (PDT) Received: from lab-ubuntu ([41.90.69.21]) by smtp.gmail.com with ESMTPSA id q15-20020a170906360f00b0099d804da2e9sm11511509ejb.225.2023.10.12.12.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:06:23 -0700 (PDT) Date: Thu, 12 Oct 2023 22:06:21 +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 v2] staging: wlan-ng: remove strcpy() 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.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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:06:39 -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 strcpy() 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 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 strcpy() 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