DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/tap: avoid memcpy with NULL arg
@ 2024-08-14  2:34 Stephen Hemminger
  2024-08-19 11:03 ` Ferruh Yigit
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2024-08-14  2:34 UTC (permalink / raw)
  To: dev; +Cc: 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.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/tap/tap_netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tap/tap_netlink.c b/drivers/net/tap/tap_netlink.c
index c7db78563a..8a57c9242c 100644
--- a/drivers/net/tap/tap_netlink.c
+++ b/drivers/net/tap/tap_netlink.c
@@ -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);
 }
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/tap: avoid memcpy with NULL arg
  2024-08-14  2:34 [PATCH] net/tap: avoid memcpy with NULL arg Stephen Hemminger
@ 2024-08-19 11:03 ` Ferruh Yigit
  2024-08-19 11:04   ` Ferruh Yigit
  0 siblings, 1 reply; 4+ messages in thread
From: Ferruh Yigit @ 2024-08-19 11:03 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

On 8/14/2024 3:34 AM, Stephen Hemminger wrote:
> Calling memcpy with a null pointer even if zero length is
> undefined, so check if data_length is zero.
> Problem reported by Gcc analyzer.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> 

Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>
Applied to dpdk-next-net/main, thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/tap: avoid memcpy with NULL arg
  2024-08-19 11:03 ` Ferruh Yigit
@ 2024-08-19 11:04   ` Ferruh Yigit
  2024-08-19 15:10     ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Ferruh Yigit @ 2024-08-19 11:04 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, Thomas Monjalon, David Marchand

On 8/19/2024 12:03 PM, Ferruh Yigit wrote:
> On 8/14/2024 3:34 AM, Stephen Hemminger wrote:
>> 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?


>>
>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>
> Applied to dpdk-next-net/main, thanks.
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/tap: avoid memcpy with NULL arg
  2024-08-19 11:04   ` Ferruh Yigit
@ 2024-08-19 15:10     ` Stephen Hemminger
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2024-08-19 15:10 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Thomas Monjalon, David Marchand

On Mon, 19 Aug 2024 12:04:57 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:

> On 8/19/2024 12:03 PM, Ferruh Yigit wrote:
> > On 8/14/2024 3:34 AM, Stephen Hemminger wrote:  
> >> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-19 15:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-14  2:34 [PATCH] net/tap: avoid memcpy with NULL arg Stephen Hemminger
2024-08-19 11:03 ` Ferruh Yigit
2024-08-19 11:04   ` Ferruh Yigit
2024-08-19 15:10     ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).