Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp856178rdg; Fri, 13 Oct 2023 03:22:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkKolaZvAffR5Di2BHw8V1e3UtuQAYY0+J0GybnDR5Ys7bDt53Ph8kpdzuBlHZObMKe0jf X-Received: by 2002:a05:6a20:9191:b0:16b:e46e:1246 with SMTP id v17-20020a056a20919100b0016be46e1246mr23249601pzd.30.1697192573536; Fri, 13 Oct 2023 03:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697192573; cv=none; d=google.com; s=arc-20160816; b=bpOSPbwezKfmxLsQuH/XH0zgcz//NC+cwsVc9h5Chn2l6lu2sPV9ZtodBQqvIphvuD b3xigc4n1G1lbTE/Y6ECEimDINMtJQG7/0cF8ffI3NjpgJm033A9kf6MoRTS50g9fsgc uGBUbJ24gx4ivAvXueoIdmAT5nCNBOiPuhegu4Eym5VVdkR5xkroo+RlnPhWsmkCamoj a2RqAbjvF+dXTSvM1x96dPdgBw3yVwmgwSkUG4yvgZaaZwvGmcyU+eBD+veshAl2p/BS jFXczvI1iiO4Fqvy4L1rDz01l2vn3YnYMFLlYD9+l5upr58tM+rvOsCmzm2CR1iLDUDy sFtw== 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=QrZvb5Q0DoAOQSgSrWjje0teuv1ya0EsyrCeefTKeuE=; fh=nGLMTMRLxTn+amOEWRy0k9ZhwiE+Ja/qghQ1xIi9ljM=; b=qbfiQ5MkzaEjmQKgVk8ehA3G2wr+T0tgJoaOjbg2E53L6S16sLe4UjV6h3YJa0CxdS 0kYbgsQsOrE/lEH+CqscMG48xnYMSNsvEtctcFC3uibZyOIb9DlL4vO9yh+wyME1cMeY CJv2RdC336nh5TAs3JcKdnXI9ZVnZmy2fXJXYU+2End3ZECqm5cd4Kly1gBNQkRrNFS9 jK02vchffjX6+aDcuR8L+ZPxZ/mEOa+ztPUPnRK9oIP2H4HDW9i/djIRUIjldX5mDkzp Rkb+M9YE/r5aeWcIOuoUxJiU5XPKbIph+1/HiJ7goYAgQTCwQN/LSOJ4f2G26niBuP+I Pwrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YIdytFzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h14-20020a170902680e00b001c9ca0a03dcsi3935213plk.86.2023.10.13.03.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 03:22:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YIdytFzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 9CE33807D9AD; Fri, 13 Oct 2023 03:21:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbjJMKVa (ORCPT + 99 others); Fri, 13 Oct 2023 06:21:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbjJMKV2 (ORCPT ); Fri, 13 Oct 2023 06:21:28 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29313CA for ; Fri, 13 Oct 2023 03:21:26 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-9b2cee40de8so388433566b.1 for ; Fri, 13 Oct 2023 03:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697192484; x=1697797284; 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=QrZvb5Q0DoAOQSgSrWjje0teuv1ya0EsyrCeefTKeuE=; b=YIdytFzJacEg0BhK2lSXeiXB+KwDXynZqBKr5hTBFFj75bwj/65xJwXBfGYjGHdfWk dWREctCNo15PEScpKMtRJMKkJHJoN9TaLrLApVcwDPWsqiMYYDY81sgYJGMZ2YcKShdS lxJFVpdbSJwwRzv2/33/veC7wtWnHsqdejqhH9uLgPp5+1jxpvitIM7nEsXVC+TS5UNl k3xY66qOw3/XNeEzXViyBSaLNn6qbooMa1DZNchG+9KTNdV1TVlEqfe4wMtsX6xWQQSm rbKrgix/rdyHxuypAcOpdoqFAaK4zqkhx/eb0Ccml+oHueZToRX0v7beQ3Lu9ah9j0Vt sfKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697192484; x=1697797284; 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=QrZvb5Q0DoAOQSgSrWjje0teuv1ya0EsyrCeefTKeuE=; b=sBUMu0dQ8qACjTreCoc046jmCSNCYRzpDhaLz47q6QtOQYUnUOdFOSpjyv+dkURS6L bWqo9i2vgbRbeBLkZf8PnkHajLboO6wyFymwiwmobg02o/vngZFz9rhSGwlleMkYX5AZ Wc7SgakD1BUW4Ms6hIBPY8N0Vj9GQAjYoaIVNum2+JJSkgjV2nApXoUIDde16/vEzaw7 9wTS9V47t7i6zcYgE9Ddy1737kMfyVgOpfVHaKSfkbnpqU5nVDsJFZhuoCsHZlOmaj5k RaK7IZnl9dIfqFTUxg0jNhGjFsToo8bIMFR4yXsmMhc7fmDCXlZ3g/e9UphHEXTW9ZQQ kobA== X-Gm-Message-State: AOJu0YxawTOejLMO6SmAZh6t/vLeAC7/SbAzQVGwKnvMsD4mhzCPEVFJ xayD/2Im2xHo0RVCxZKyc1wcQAWVVp5IBF5b X-Received: by 2002:a17:907:9306:b0:9bd:a66a:a22 with SMTP id bu6-20020a170907930600b009bda66a0a22mr874520ejc.15.1697192484138; Fri, 13 Oct 2023 03:21:24 -0700 (PDT) Received: from lab-ubuntu ([41.90.69.21]) by smtp.gmail.com with ESMTPSA id ci24-20020a170906c35800b009a2235ed496sm12395302ejb.141.2023.10.13.03.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 03:21:23 -0700 (PDT) Date: Fri, 13 Oct 2023 13:21:21 +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 v5] 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 13 Oct 2023 03:21:38 -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 v5: Removed v1 patch details from the revsion history 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); } -- Calvince Otieno