Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7588320rwd; Tue, 20 Jun 2023 03:31:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mjoqi+GRtAYUN7UOoDufdmjnozVd3/dSHR8Lcu6g6WuPLWxI8tHEsXIUC+yvc854oZ2s2 X-Received: by 2002:a67:fe88:0:b0:440:b2ba:1548 with SMTP id b8-20020a67fe88000000b00440b2ba1548mr2375325vsr.5.1687257098628; Tue, 20 Jun 2023 03:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687257098; cv=none; d=google.com; s=arc-20160816; b=VAvY8BWwxWs+5qgDaNOtIhnvaGPhwPe/fFDHthuZlfzYx4T8VFusK5oOb9Ld1rI7FI XupWpzf98st5U7T8KhOtnXHDpPcFqGhPA43X1LRKTU3GvVuzxRlXBPe+fT+R5Y6yH8iz Ga603c0v/byBYdRtxT5XydQdI0esGGbko575xjra582cWelJpbZlIahDYIYBWQMQ9h35 BoxpRRMAhOyI2yM3QKMxpDijCbvRG4+IORPdrwsB51rzjLPAfbb6tYvZTxu5gGJiI2yB krDSiylUUmwYhixh2ZCwCm6bGN3UDsmmPBwWoEq7DwGfu44tH7wxgEytOiZxnj4zdvxw y1Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=HkCFXEEnrmStviwzT132w8G9XgVYgvZO3eEETWC5ipQ=; b=m6ojUIvsDR8o133qZdXdqxxd90qVipyIUCtRNCgMhk9lFf8Wfk9G+qHCA68UvGogPJ cBLN1dcWCVOOhyowai2OZ7arj7Fb1qHC0BwkTyMsFXNUY9qsQXNP4JqV+dwmfGpBS+P2 VnDDn7spDm872xQIywufIodMfsuneG7EKmVXWDrryM8z35ojoZTmb1h0tfApsFZi2AOs peeZnqukZcdaUQAQdb7xKrl8iNEKw4tKfJtGAvR/ud8xSK7Rig2nw98V2xPmMdBVBT9s Vd9m6vRvCkXofs/21Usy2zhYlQWKT4LcPTyaIJB6pwoaxhC92M0/LR0K8/oOliZUMEa+ 97fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b="KVuth/lC"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020a63340e000000b0054fb9698c4esi1458866pga.499.2023.06.20.03.31.26; Tue, 20 Jun 2023 03:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b="KVuth/lC"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231540AbjFTKKe (ORCPT + 59 others); Tue, 20 Jun 2023 06:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231574AbjFTKKc (ORCPT ); Tue, 20 Jun 2023 06:10:32 -0400 Received: from forward101c.mail.yandex.net (forward101c.mail.yandex.net [178.154.239.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7CA1A3 for ; Tue, 20 Jun 2023 03:10:28 -0700 (PDT) Received: from mail-nwsmtp-smtp-production-main-45.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-45.sas.yp-c.yandex.net [IPv6:2a02:6b8:c14:c83:0:640:84f9:0]) by forward101c.mail.yandex.net (Yandex) with ESMTP id 18E2A600DC; Tue, 20 Jun 2023 13:09:48 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-45.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id d9eIllrDZ0U0-P5L736Pz; Tue, 20 Jun 2023 13:09:47 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1687255787; bh=HkCFXEEnrmStviwzT132w8G9XgVYgvZO3eEETWC5ipQ=; h=Message-ID:Date:Cc:Subject:To:From; b=KVuth/lCRErk4FPsqJuxEAuy6OZ+fRivkSS/1zCaqu4XarCGstj71mxwelX+1brLR 26AJ1FslZw89VAVRK+wMOwh9Xws+ZLU5FpPXL5dc3Zj0kTS3qnZ/CMixOO25MLyqdZ 6I+RtbVWfnQACHF0Drwe1NgXupimWxM7isdQRb7g= Authentication-Results: mail-nwsmtp-smtp-production-main-45.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Christophe Jaillet Cc: Kalle Valo , linux-wireless@vger.kernel.org, Dmitry Antipov Subject: [PATCH 1/2] [v2] wifi: mwifiex: avoid strlcpy() and use strscpy() where appropriate Date: Tue, 20 Jun 2023 13:07:36 +0300 Message-ID: <20230620100803.519926-1-dmantipov@yandex.ru> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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-wireless@vger.kernel.org Prefer 'strscpy()' over unsafe 'strlcpy()' and 'strcpy()' in 'mwifiex_init_hw_fw()' and 'mwifiex_register_dev()', respectively. All other calls to 'strcpy(adapter->name, ...)' should be safe because the firmware name is a compile-time constant of known length and so guaranteed to fit into a destination buffer. Signed-off-by: Dmitry Antipov --- drivers/net/wireless/marvell/mwifiex/main.c | 11 +++-------- drivers/net/wireless/marvell/mwifiex/sdio.c | 4 +++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wireless/marvell/mwifiex/main.c index ea22a08e6c08..64512b00e8b5 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.c +++ b/drivers/net/wireless/marvell/mwifiex/main.c @@ -724,14 +724,9 @@ static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter, /* Override default firmware with manufacturing one if * manufacturing mode is enabled */ - if (mfg_mode) { - if (strlcpy(adapter->fw_name, MFG_FIRMWARE, - sizeof(adapter->fw_name)) >= - sizeof(adapter->fw_name)) { - pr_err("%s: fw_name too long!\n", __func__); - return -1; - } - } + if (mfg_mode) + strscpy(adapter->fw_name, MFG_FIRMWARE, + sizeof(adapter->fw_name)); if (req_fw_nowait) { ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name, diff --git a/drivers/net/wireless/marvell/mwifiex/sdio.c b/drivers/net/wireless/marvell/mwifiex/sdio.c index a24bd40dd41a..a5d3128d7922 100644 --- a/drivers/net/wireless/marvell/mwifiex/sdio.c +++ b/drivers/net/wireless/marvell/mwifiex/sdio.c @@ -2483,7 +2483,9 @@ static int mwifiex_register_dev(struct mwifiex_adapter *adapter) if ((val & card->reg->host_strap_mask) == card->reg->host_strap_value) firmware = card->firmware_sdiouart; } - strcpy(adapter->fw_name, firmware); + ret = strscpy(adapter->fw_name, firmware, sizeof(adapter->fw_name)); + if (ret < 0) + return ret; if (card->fw_dump_enh) { adapter->mem_type_mapping_tbl = generic_mem_type_map; -- 2.41.0