Skip to contentSkip to conversation

net: rtnetlink: fix correct size given to memset

PATCH In review Francois-Xavier Le Bail 3 participants 4 messages Feb 11, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: rtnetlink: fix correct size given to memset

Find by cppcheck:
[net/core/rtnetlink.c:1842]: (warning) Using size of pointer linkinfo instead of size of its data.

---

The diagnosis of cppcheck seems relevant.

 net/core/rtnetlink.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnetlink.c +1 -1
index 048dc8d..9a5dbf1 100644
@@ -1839,7 +1839,7 @@ replay:
 		if (err < 0)
 			return err;
 	} else
-		memset(linkinfo, 0, sizeof(linkinfo));
+		memset(linkinfo, 0, sizeof(*linkinfo));
 
 	if (linkinfo[IFLA_INFO_KIND]) {
 		nla_strlcpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));
#1 lore raw
Quoted 16 lines · Francois-Xavier Le Bail

Find by cppcheck:
[net/core/rtnetlink.c:1842]: (warning) Using size of pointer linkinfo instead of size of its data.

---

The diagnosis of cppcheck seems relevant.

 net/core/rtnetlink.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnetlink.c +0 -0
index 048dc8d..9a5dbf1 100644

net/core/rtnetlink.c replay: · line 1845

Quoted 8 lines
net/core/rtnetlink.c +1 -1
@@ -1839,7 +1839,7 @@ replay:
 		if (err < 0)
 			return err;
 	} else
-		memset(linkinfo, 0, sizeof(linkinfo));
+		memset(linkinfo, 0, sizeof(*linkinfo));
 
 	if (linkinfo[IFLA_INFO_KIND]) {
 		nla_strlcpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));

This is absolutely wrong.

	struct nlattr *linkinfo[IFLA_INFO_MAX+1];

sizeof(linkinfo) is totally appropriate

sizeof(*linkinfo) is equal to sizeof(void *), and this is not what we need here.

#2 lore raw

From: Eric Dumazet

Quoted 29 lines · Francois-Xavier Le Bail
Quoted 16 lines

Find by cppcheck:
[net/core/rtnetlink.c:1842]: (warning) Using size of pointer linkinfo instead of size of its data.

---

The diagnosis of cppcheck seems relevant.

 net/core/rtnetlink.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnetlink.c +0 -0
index 048dc8d..9a5dbf1 100644

net/core/rtnetlink.c replay: · line 1845

Quoted 8 lines
net/core/rtnetlink.c +1 -1
@@ -1839,7 +1839,7 @@ replay:
 		if (err < 0)
 			return err;
 	} else
-		memset(linkinfo, 0, sizeof(linkinfo));
+		memset(linkinfo, 0, sizeof(*linkinfo));
 
 	if (linkinfo[IFLA_INFO_KIND]) {
 		nla_strlcpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));

This is absolutely wrong.

Quoted 6 lines
	struct nlattr *linkinfo[IFLA_INFO_MAX+1];

sizeof(linkinfo) is totally appropriate

sizeof(*linkinfo) is equal to sizeof(void *), and this is not what we need here.

I guess that changing it to:

	memset(&linkinfo, 0, sizeof(linkinfo));

might make the tool happy, but it really ought to be taught about arrays.

David

#3 lore raw
In reply to Eric Dumazet
Quoted 15 lines

From: Eric Dumazet <[email protected]>

To: Francois-Xavier Le Bail <[email protected]>

Quoted 2 lines

Find by cppcheck:
[net/core/rtnetlink.c:1842]: (warning) Using size of pointer linkinfo

instead of size of its data.

Quoted 9 lines

---

The diagnosis of cppcheck seems relevant.

  net/core/rtnetlink.c |    2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 8 lines

This is absolutely wrong.

    struct nlattr *linkinfo[IFLA_INFO_MAX+1];

sizeof(linkinfo) is totally appropriate

sizeof(*linkinfo) is equal to sizeof(void *), and this is not what we need here.

Oops, sorry for the noise.