Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp812994rdg; Fri, 13 Oct 2023 01:39:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0d+z5V03sETdK0eHoRj8/b8wu9RXTrDhHXa3WTe+sIg6ct7mQePJpZAQUvszhsn0cGEFY X-Received: by 2002:a17:903:1247:b0:1c4:3cd5:4298 with SMTP id u7-20020a170903124700b001c43cd54298mr32521428plh.18.1697186388170; Fri, 13 Oct 2023 01:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697186388; cv=none; d=google.com; s=arc-20160816; b=Whal+jijlDp1Wzurnli5ZE0EqT6qDYlKX47HBa6cSvov+CsfzLieD98ML//t1dpMMB 3E7LKF/EUzGcZMu27gQ0lEVozTcFrXN+8QtqzEmxqQFvitmNu+cKlPhsSQIptKPgM2CT +CO+r3H6UG685v72RRm3ggUriwuz7AzUjvE9VrNH9GQ10Yc6UuumUfcK8TRzVn+n3I2n GXMGDVqfIWpjQibTt6aVedb/A2HztH3FAmf0JDh8NcQCkrOsWiqcK686qut8cs8vzpbU u6VQ/p2ohtq5+CNU9aj+wCr+jqOqCOMaHdQ0Ah5RFkMUre0ohJuyyzjyk5ssPen7ijD6 56Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qdwDG1vEaBdbFUB+whbPTpmPJ6lJzSaWGwO7+4KqPYE=; fh=MArzYZ/i4IDOZnhQVk9AO9Nf667jvVcBzKX9aYqxVs4=; b=n/oKewTBqRq1WzXNcnoVl/BBAN/BVS6X+vD4dJRA3KZeJV/T3z5mJq2dy8zOMmp53r K7EIDeYyksxq2M1VeamNZ7RHvhNYssgJc9fObREAo0H66sOZiJHlsrSFql7LamzO/vH+ Ry4sD6W54NOzW1E2wQPRrFeNEYoEJqH9W+ZJW/gzCl67HDM/v3m/mOq8m7pbQzCFajsb VUpw8CrrewHjZk5wPYPVQ9ZjhQ1Li0pZR6pplsRC2QoaUxlIHIiSP2dNerT8XyQ7359U o9cITUhUzCBanIZmWPnDsx801u53Du8mai8QbOzDx/4Ca485ctzqyKo1L/eHe31Do0SJ qTqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rDSQXf17; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id a10-20020a170902ecca00b001ae40e07fb0si4408392plh.216.2023.10.13.01.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 01:39:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rDSQXf17; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7C09081F390C; Fri, 13 Oct 2023 01:39:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbjJMIj3 (ORCPT + 99 others); Fri, 13 Oct 2023 04:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230250AbjJMIjZ (ORCPT ); Fri, 13 Oct 2023 04:39:25 -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 C2A3B107 for ; Fri, 13 Oct 2023 01:39:11 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40572aeb73cso19684205e9.3 for ; Fri, 13 Oct 2023 01:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697186350; x=1697791150; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=qdwDG1vEaBdbFUB+whbPTpmPJ6lJzSaWGwO7+4KqPYE=; b=rDSQXf17kwmVXFj40LZgFnpLKcC/W+av5f4nFTNWd5b9XMBrKsZH+GCkyi+heY39Sa bygivT+EnZ57M2puNlsGiYB5TyH3x591LhLEGweaoB5LFjtgZSM+kdS/fmHbWvN0jc7b vBiGKnGN4+0sDN2Df3t3A1Z/ujvdUyF9ukQszF6+TXprXAKqGGPqa6vu5Vg+q8CE+rsm nZU4q3RKAKWR1mQoFEbhhFHenRqpM1SiVotpeF8J5nZeirIY0XphPaHYBoW2UZc79wR1 5szBQpoE7zZJ07G4dts+iYqgaBa/hiXYdthWclW1tHJCkzbdLUcljBnS2uWjuOXLxbUq r0NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697186350; x=1697791150; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qdwDG1vEaBdbFUB+whbPTpmPJ6lJzSaWGwO7+4KqPYE=; b=J2IZZBouSqaXAmwwywtgWN8BfD0FQG2jZ7XF+6XDwY8kAB+SRHi67LV2q2Bag7u7iU pBWP/G1Bi8/bFHg5lxTX21D3GpXzEPsjIAtmHu+I2vkvTLgl+Qn690jCEDEMKCT5pJEP RtrKBJ88niybaMWfmPuGR7e/Nd6nLTh5cKNCuDqWLIVKkG3k7+wSlt0nYcmJh/GvVEp2 v8x8GWtqq3oijsKi582c+Rauz73u86SNTmGRmNgz74C79P4p2mdOIKdBqpMsAO09Xkni fxOBiVqCoqXDwDXESCLaanT2w5FHglbD+8X0L24R9W56YWGxE/Ja+aqIRk/CMn5IxB51 k4ig== X-Gm-Message-State: AOJu0YwOEYFLxT81BztHp2y1yfNkBVBk6rEsTJi+stw+QR/PHekPfTHx shdeT3i7M1FPSBrh9Cp/mfo/KQ== X-Received: by 2002:a05:600c:21d1:b0:405:3ae6:2413 with SMTP id x17-20020a05600c21d100b004053ae62413mr23348145wmj.25.1697186349795; Fri, 13 Oct 2023 01:39:09 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id n25-20020a1c7219000000b003fe1c332810sm1901966wmc.33.2023.10.13.01.39.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 01:39:09 -0700 (PDT) Date: Fri, 13 Oct 2023 11:39:06 +0300 From: Dan Carpenter To: Calvince Otieno Cc: outreachy@lists.linux.dev, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Archana , Dan Carpenter , Simon Horman , Bagas Sanjaya , linux-staging@lists.linux.dev Subject: Re: [PATCH v2] staging/wlan-ng: remove strcpy() use in favor of strscpy() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 01:39:45 -0700 (PDT) On Thu, Oct 12, 2023 at 05:01:57PM +0300, Calvince Otieno wrote: > 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. Ok, the original code also ensured that the destination string was NUL terminated. Here is what I want this commit message to look like: === Checkpatch encourages everyone to use 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 > --- v2: Update the commit message. Remove the " - 1" from the strcpy(). regards, dan carpenter