Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1567493lqe; Mon, 8 Apr 2024 12:48:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXWWVW2PcjTaq4w9KY/fOrp7Wsb0JhuPqs/3DAoYKdjBRz9x6PZj1pzYUk+idR8aY69MM54cZvmL3aQ4UvJ+RhLDg8cFTPSfhDkKXhANw== X-Google-Smtp-Source: AGHT+IE/aKXugdtSoGteZ7d2ORMOrKcPOoQyWJQC4jiHqEYlkWEFQUABcvLNSXucj+J8ylN10pNs X-Received: by 2002:a05:6a20:dd87:b0:1a7:56d2:66bb with SMTP id kw7-20020a056a20dd8700b001a756d266bbmr4484249pzb.24.1712605730941; Mon, 08 Apr 2024 12:48:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712605730; cv=pass; d=google.com; s=arc-20160816; b=xjZXkFrUZJ7v/Ep5e1xWqGriMYzFySZFwAbnYIazpqf0slWFFLV08iheYCGw/4ckAW XuL4xVBg065EPbC3+5dBlr8iXHYDZGHLb1uSKQMvU8VdiJoVhdThop6y16HnCTFfzOWs ue/u8ncLAZ/a3+ZDVLg85b5k4aJJcB3dF56o88UbDNaF0KdWbnwwGer7xwha9IPqD1z5 9s4VkUWV/sPxCcEDH3cSP+RcQ35kYarPQOB/TxIpNpi+I1ex6o9Jsyl9IubHxjnnJbvn tgvZfui7rmXCyel40FPaXedcrgXrGjGtBQpnM/nj7GJ/ERaICXo9LvA8NfWHndrZdGWf sl8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fYteMY71aS9hNlo9rDCosVYIp8S76O5SU4CJSOpoOmQ=; fh=oPc7+CFTtLNnxZTnr6M/hGwhI1EXh4B7mGguA0Nolno=; b=Lio/vZ9nTSoaABrspEBdazKBjFL/k/WMOWzkGDyTvTs7PQtQxr+2wfCU2hiq8x2OBG v0gWkA0AFh3puZ9Ts2RtNYT0yN5fnYZjAVee6410D/3YkclbpuvxYl8xk8GC8KxcUKIF NEzoph32chxYJ7SXXDknBnHZyK/J3fuZ9fXyqMcSKCweElmGsHqQmzvTXNxpzDvIZgGN SZQHGSp2Hfo7ZKYuo1S5G5utGcpJAblt4GhPb1F/bHoKV5bQVVCrTE7r+OKpoSLTZF+1 mdI3cMteu4K9/yEsuknGr+NDUqBBqZ6MO+ZUXZyKtmSXprxaoCwoFWQf99ME8fOtifIy 5KKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eWH+cejr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-135886-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135886-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lm16-20020a170903299000b001e3d3ac40c6si5493656plb.8.2024.04.08.12.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 12:48:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135886-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eWH+cejr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-135886-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135886-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 88FDF281D2E for ; Mon, 8 Apr 2024 19:48:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED491146A60; Mon, 8 Apr 2024 19:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eWH+cejr" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C187146595; Mon, 8 Apr 2024 19:48:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712605719; cv=none; b=gJUUgdUfADUifutrlqwMcHNagTmBhLpUIDOI84B1PV3y4NUCTzR6Bmf8MAQYHFXkHseX7olVu6TL8r+eUTgUqZtub6T6pTr5wJiX5EgHpOSL1X+DJE82hue0tUaCVWzsoR2drIefW84RJdQYeMob+vI2h6h9YkjvbjkIlfW5Iwg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712605719; c=relaxed/simple; bh=CslybNzY6McotszEiRDesoqYQQUvU/zYFyq3VeTUCCs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rHm1yU9z313IChOR3xzplfakG5JoM6y4eR2ek7v7V4nGf9RH5uAJoLV6vs2pAgmYcrxJ6RFoQoaJdvFCJ5jJVQhuWMsU+kYfoQLLU67raOA9uN9Z/fsDheSkFUjfn9QVPFmcKr+scx41wUs5Hb6N3um2P/jdHMouHqaJHqp39Ps= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eWH+cejr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B726C433F1; Mon, 8 Apr 2024 19:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712605718; bh=CslybNzY6McotszEiRDesoqYQQUvU/zYFyq3VeTUCCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eWH+cejr3PKPTR9GLjP5NsIiQfZQmb+hbRJcqcbielxZh0LpNgtB0ybhKjgCjb+UL 3saf8CT5L32i8qv6Vxyz2pJk/2qqPh0FTrDZNcVnhZBmPxf72jmo+XJh2rjcpkLYLX yPztgBTGpA978M+O05O7WzW1Al9G7N01TPoY8EgBkkjBQBadXk5rhsQBs1KAILrYhI D6GxqZUb3rH4Z7WLFzHgzvduNm90gFcY1WfGINlpRhFZUL0IUbP6LuZWSEezX++/Ws 88RYonKxwTS4GKZvpPGTIG56zWnagW+1whUG5HMaDA9J5lDW3TguXymTIR6/pbmXqw v4Y6qoQCy+Rdw== From: Arnd Bergmann To: Greg Kroah-Hartman , Nathan Chancellor Cc: Justin Stitt , Dan Carpenter , Arnd Bergmann , Nick Desaulniers , Bill Wendling , Franziska Naepelt , Johannes Berg , Jeff Johnson , Aloka Dixit , Erick Archer , Yang Yingliang , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 2/3] [v2] staging: rtl8723bs: convert strncpy to strscpy Date: Mon, 8 Apr 2024 21:48:10 +0200 Message-Id: <20240408194821.3183462-2-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240408194821.3183462-1-arnd@kernel.org> References: <20240408194821.3183462-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Arnd Bergmann 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 --- v2: use the two-argument version of strscpy(), which is simpler for the constant size destination. Add the third instance in this driver as well. --- drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 5 ++--- drivers/staging/rtl8723bs/os_dep/os_intfs.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c index 65a450fcdce7..3fe27ee75b47 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); 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); mon_ndev->needs_free_netdev = true; mon_ndev->priv_destructor = rtw_ndev_destructor; diff --git a/drivers/staging/rtl8723bs/os_dep/os_intfs.c b/drivers/staging/rtl8723bs/os_dep/os_intfs.c index 68bba3c0e757..55d0140cd543 100644 --- a/drivers/staging/rtl8723bs/os_dep/os_intfs.c +++ b/drivers/staging/rtl8723bs/os_dep/os_intfs.c @@ -415,7 +415,7 @@ static int rtw_ndev_init(struct net_device *dev) struct adapter *adapter = rtw_netdev_priv(dev); netdev_dbg(dev, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter)); - strncpy(adapter->old_ifname, dev->name, IFNAMSIZ); + strscpy(adapter->old_ifname, dev->name); return 0; } -- 2.39.2