Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp842714rdg; Fri, 13 Oct 2023 02:54:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMf8bF5PGmvqLXdtAaepEQD4/+eKrDGuQ7X08dRVZZmzAwJjrrYAJYsyokvINXsAkIr1ZP X-Received: by 2002:a17:90b:38c9:b0:268:b0b:a084 with SMTP id nn9-20020a17090b38c900b002680b0ba084mr24044854pjb.46.1697190891601; Fri, 13 Oct 2023 02:54:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697190891; cv=none; d=google.com; s=arc-20160816; b=Fcb8J7VjLsJo/0q/+AhMKWiuMfsjcc/+4y3/upRRkvUElCsWzNfriKyec/Dr6zIts4 4MEqJcaQH+8XDTPpjQumutik+EVqt7B/Bzim+r7RY0uXZmOAl4sE4j4a2Y4G+Qif3Wx5 jSBEyF7qWYRRggCmp2z2KoplwIKwKUMtwqq7ce1nf6fDORVXWwPKs/6jhwIw9Qz+9B8k VlbWKNjr5IRwPNzn0dcr66VUIj+gz8MrSOVXJ6/RxRYUvW64IVphX1f/oh0frO1HhEEw qT2qh4GaTTAyycneueseBnYUsUTYKH6pzTVPX38QWR/VCbrnHIpm4KtT0DXOCByXYlCV QEGQ== 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=R4NoCUDvuhISs5zePSgTjBOD4p4v9fCoCqCDFPnEEaM=; fh=nGLMTMRLxTn+amOEWRy0k9ZhwiE+Ja/qghQ1xIi9ljM=; b=oGrx4UrjyAUlTxELDgZokpFNuJ9cY75TG3R6LOPLRoB4QzqA9W188bfRtN0fm8pZKX 0AkyRqQeYabqiz1a8j/yJbbMjlX7mKCW05iLrxlrJgmxYHOQ5ZtB40WsGkPEk+6V59lm Mw3IGClh4twHcctjcbF7MvseVpvt91xzbk+jfZbnbX4oJPRwxr7c0L7VQWuSRfyMnjqJ 1Tn2zW5VVJs57BxxaZ/GCAfSeuFuyRyc2ogMH9BbMo70ECq/+xeOGYhODSJAzOhIk2Kz lFEwm11+C54pWNN/IsuVeNOPZvUSCeBi3l48Otz7yp6Jy0UPhlg99QKC6v35ByU8bNUT aJRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Rhz0IU0L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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. [23.128.96.31]) by mx.google.com with ESMTPS id h62-20020a638341000000b005aaf29151acsi1111338pge.834.2023.10.13.02.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 02:54:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Rhz0IU0L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 0BF9C81E143E; Fri, 13 Oct 2023 02:54:49 -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 S231307AbjJMJye (ORCPT + 99 others); Fri, 13 Oct 2023 05:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbjJMJyd (ORCPT ); Fri, 13 Oct 2023 05:54:33 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8945C95 for ; Fri, 13 Oct 2023 02:54:31 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c5056059e0so8661561fa.3 for ; Fri, 13 Oct 2023 02:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697190869; x=1697795669; 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=R4NoCUDvuhISs5zePSgTjBOD4p4v9fCoCqCDFPnEEaM=; b=Rhz0IU0L2XHIjU6aNNUMX/yUxHX6xTD63CWHdzvY5GEgLfPfveeoQk0mapfDnDo/4n dptyINKR/DfBfwTjl/CaWLFn6coogMfgJ3AluD5C4crzFIqB5dxLXMz/65L6qVrhtDgX f9V7qNhV9lNRD4sAMDyLJ+XpuDK5mBG/3PBNFlC7sc9oq2QlkUuVTs96t/6A1LUJLo0c RGj2Vd9eeKhNoCjmdfHHEUpRJZM1/7oBc///E0wwardj9iqq+abazBdMNXm8dZsJeqrQ myEQHyIoEnyniZ/uZbdVVCbW7m9CR3y0J3P3EjeHU8dmP6/uQnLcooTHdywz5fIbWyXi /ISg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697190869; x=1697795669; 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=R4NoCUDvuhISs5zePSgTjBOD4p4v9fCoCqCDFPnEEaM=; b=bjVwEtRx8ka8hvD4h6NuzPtCMQbATmocUhVHg+Ki3Ohd57KZuZRLhtemLD3SdDpPWO TTAVarAZZSNDFCYgS3RqymIaww9E6CL4hvv5s1gpsQudh2+YSJi/g1vAP8XWs30gL3bC 3i7uHB+BfHS42wJdfC8csA9Hb6KFTIcS8aIAKcxFL8RbsijLF1k1ZXheGn9TifhJfqkW gtEgVDuCWrHhHRKmgDCAYmh7fF4/Z9mihKMk/zNlNbCpx7V165itNNVNk4qzG+WsE5Ex ouslWAYpIU3VK4KY8vrTISSFG7hEjbOyHX1T/F2oT+yquwMZCAd98nX8uPCXEYxvtgp+ fBFA== X-Gm-Message-State: AOJu0Yx3Tlcg53LBrJiBXdTQCPmAaYGhOyyK1xFo0BYMwbVRq7D4qS/3 bLMoieUgsVVcutReqmuLI3BEtEX+YetqXChS X-Received: by 2002:a19:910d:0:b0:501:ba04:f34b with SMTP id t13-20020a19910d000000b00501ba04f34bmr19743563lfd.44.1697190869138; Fri, 13 Oct 2023 02:54:29 -0700 (PDT) Received: from lab-ubuntu ([41.90.69.21]) by smtp.gmail.com with ESMTPSA id c26-20020a056402101a00b00533e915923asm11199706edu.49.2023.10.13.02.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 02:54:28 -0700 (PDT) Date: Fri, 13 Oct 2023 12:54:26 +0300 From: Calvince Otieno To: outreachy@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Luke Koch , Bagas Sanjaya , Simon Horman , Calvince Otieno , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4] staging: wlan-ng: replace strncpy() 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]); Fri, 13 Oct 2023 02:54:49 -0700 (PDT) Checkpatch suggests the use of strscpy() instead of strncpy(). The advantages are that it always adds a NUL terminator and it prevents a read overflow if the src string is not properly terminated. One potential disadvantage is that it doesn't zero pad the string like strncpy() does. In this code, strscpy() and strncpy() are equivalent and it does not affect runtime behavior. The string is zeroed on the line before using memset(). The resulting string was always NUL terminated and PRISM2_USB_FWFILE is string literal "prism2_ru.fw" so it's NUL terminated. However, even though using strscpy() does not fix any bugs, it's still nicer and makes checkpatch happy. Signed-off-by: Calvince Otieno --- Patch version v4: Provide a valid description of the patch 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