Skip to contentSkip to conversation

net/tap: avoid memcpy with NULL arg

PATCH Applied Stephen Hemminger 2 participants 4 messages Aug 14, 2024 – Aug 19, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/tap: avoid memcpy with NULL arg

Calling memcpy with a null pointer even if zero length is undefined, so check if data_length is zero. Problem reported by Gcc analyzer.

---
 drivers/net/tap/tap_netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tap/tap_netlink.c +2 -1
index c7db78563a..8a57c9242c 100644
@@ -302,7 +302,8 @@ tap_nlattr_add(struct nlmsghdr *nh, unsigned short type,
 	rta = (struct rtattr *)NLMSG_TAIL(nh);
 	rta->rta_len = RTA_LENGTH(data_len);
 	rta->rta_type = type;
-	memcpy(RTA_DATA(rta), data, data_len);
+	if (data_len > 0)
+		memcpy(RTA_DATA(rta), data, data_len);
 	nh->nlmsg_len = NLMSG_ALIGN(nh->nlmsg_len) + RTA_ALIGN(rta->rta_len);
 }
 
Signature · 1 line
2.43.0
#2 lore raw
Quoted 5 lines · Ferruh Yigit
Quoted 4 lines · Stephen Hemminger

Calling memcpy with a null pointer even if zero length is undefined, so check if data_length is zero. Problem reported by Gcc analyzer.

Btw, how do you run the GCC analyzer?
Is this something can we add to our CI checks?

Quoted 7 lines
Quoted 3 lines

Applied to dpdk-next-net/main, thanks.

#3 lore raw
Quoted 9 lines · On Mon, 19 Aug 2024 12:04:57 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 5 lines · Ferruh Yigit
Quoted 4 lines · Stephen Hemminger

Calling memcpy with a null pointer even if zero length is undefined, so check if data_length is zero. Problem reported by Gcc analyzer.

Btw, how do you run the GCC analyzer?
Is this something can we add to our CI checks?

I just added it to cflags in meson build.
Tap only had this warning, but mlx5 had lots of warnings.