net: rtnetlink: fix correct size given to memset
Subsystems (2)
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
@@ -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));
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.Signed-off-by Francois-Xavier Le Bail <[email protected]>---
The diagnosis of cppcheck seems relevant.
net/core/rtnetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/core/rtnetlink.c +0
-0
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.
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.Signed-off-by Francois-Xavier Le Bail <[email protected]>---
The diagnosis of cppcheck seems relevant.
net/core/rtnetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/core/rtnetlink.c +0
-0net/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 tosizeof(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
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 linkinfoinstead of size of its data.
Quoted 9 lines
Signed-off-by Francois-Xavier Le Bail <[email protected]>---
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 tosizeof(void *), and this is not what we need here.
Oops, sorry for the noise.