All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Nathan Chancellor <nathan@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	Franziska Naepelt <franziska.naepelt@googlemail.com>,
	Johannes Berg <johannes.berg@intel.com>,
	Yang Yingliang <yangyingliang@huawei.com>,
	Erick Archer <erick.archer@gmx.com>,
	linux-staging@lists.linux.dev, llvm@lists.linux.dev
Subject: [PATCH 09/11] staging: rtl8723bs: convert strncpy to strscpy
Date: Thu, 28 Mar 2024 15:04:53 +0100	[thread overview]
Message-ID: <20240328140512.4148825-10-arnd@kernel.org> (raw)
In-Reply-To: <20240328140512.4148825-1-arnd@kernel.org>

From: Arnd Bergmann <arnd@arndb.de>

gcc-9 complains about a possibly unterminated string in the strncpy() destination:

In function 'rtw_cfg80211_add_monitor_if',
    inlined from 'cfg80211_rtw_add_virtual_intf' at drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c:2209:9:
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c:2146:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation]
 2146 |  strncpy(mon_ndev->name, name, IFNAMSIZ);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This one is a false-positive because of the explicit termination in the following
line, and recent versions of clang and gcc no longer warn about this.

Interestingly, the other strncpy() in this file is missing a termination but
does not produce a warning, possibly because of the type confusion and the
cast between u8 and char.

Change both strncpy() instances to strscpy(), which avoids the warning as well
as the possibly missing termination. No additional padding is needed here.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 65a450fcdce7..98bc5520e77d 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -884,7 +884,7 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
 		goto addkey_end;
 	}
 
-	strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
+	strscpy(param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
 
 	if (!mac_addr || is_broadcast_ether_addr(mac_addr))
 		param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */
@@ -2143,8 +2143,7 @@ static int rtw_cfg80211_add_monitor_if(struct adapter *padapter, char *name, str
 	}
 
 	mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
-	strncpy(mon_ndev->name, name, IFNAMSIZ);
-	mon_ndev->name[IFNAMSIZ - 1] = 0;
+	strscpy(mon_ndev->name, name, IFNAMSIZ);
 	mon_ndev->needs_free_netdev = true;
 	mon_ndev->priv_destructor = rtw_ndev_destructor;
 
-- 
2.39.2


  parent reply	other threads:[~2024-03-28 14:07 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28 14:04 [PATCH 00/11] address remaining stringop-truncation warnings Arnd Bergmann
2024-03-28 14:04 ` Arnd Bergmann
2024-03-28 14:04 ` [PATCH 01/11] staging: vc04_services: changen strncpy() to strscpy_pad() Arnd Bergmann
2024-03-28 14:04   ` Arnd Bergmann
2024-03-28 14:42   ` Dan Carpenter
2024-03-28 14:42     ` Dan Carpenter
2024-03-28 16:15     ` Arnd Bergmann
2024-03-28 16:15       ` Arnd Bergmann
2024-03-28 23:10   ` Justin Stitt
2024-03-28 23:10     ` Justin Stitt
2024-03-28 14:04 ` [PATCH 02/11] scsi: devinfo: rework scsi_strcpy_devinfo() Arnd Bergmann
2024-03-28 16:46   ` Bart Van Assche
2024-03-28 23:14   ` Justin Stitt
2024-03-28 23:18     ` Arnd Bergmann
2024-03-28 14:04 ` [PATCH 03/11] staging: replace weird strncpy() with memcpy() Arnd Bergmann
2024-03-28 16:35   ` Dan Carpenter
2024-04-08 14:45     ` Arnd Bergmann
2024-04-08 15:59       ` Dan Carpenter
2024-04-08 19:20         ` Arnd Bergmann
2024-03-28 14:04 ` [PATCH 04/11] orangefs: convert strncpy() to strscpy() Arnd Bergmann
2024-03-28 23:17   ` Justin Stitt
2024-03-28 14:04 ` [PATCH 05/11] test_hexdump: avoid string truncation warning Arnd Bergmann
2024-03-28 23:54   ` Justin Stitt
2024-04-08 15:38     ` Arnd Bergmann
2024-04-08 19:53       ` Justin Stitt
2024-03-28 14:04 ` [PATCH 06/11] acpi: avoid warning for truncated string copy Arnd Bergmann
2024-03-28 23:20   ` Justin Stitt
2024-04-08 14:41   ` Rafael J. Wysocki
2024-03-28 14:04 ` [PATCH 07/11] block/partitions/ldm: convert strncpy() to strscpy() Arnd Bergmann
2024-03-28 23:24   ` Justin Stitt
2024-03-28 14:04 ` [PATCH 08/11] blktrace: convert strncpy() to strscpy_pad() Arnd Bergmann
2024-03-28 14:14   ` Steven Rostedt
2024-04-08 18:05     ` Arnd Bergmann
2024-03-28 14:04 ` Arnd Bergmann [this message]
2024-03-28 23:01   ` [PATCH 09/11] staging: rtl8723bs: convert strncpy to strscpy Justin Stitt
2024-04-08 18:15     ` Arnd Bergmann
2024-03-28 14:04 ` [PATCH 10/11] staging: greybus: change strncpy() to strscpy() Arnd Bergmann
2024-03-28 15:00   ` Dan Carpenter
2024-04-08 18:26     ` Arnd Bergmann
2024-04-09  7:09       ` Dan Carpenter
2024-03-28 23:28   ` Justin Stitt
2024-04-08 18:30     ` Arnd Bergmann
2024-03-28 14:04 ` [PATCH 11/11] kbuild: enable -Wstringop-truncation globally Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240328140512.4148825-10-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=erick.archer@gmx.com \
    --cc=franziska.naepelt@googlemail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johannes.berg@intel.com \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=yangyingliang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.