* [PATCH] net: rtnetlink: fix correct size given to memset
@ 2014-02-11 14:06 Francois-Xavier Le Bail
2014-02-11 15:28 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Francois-Xavier Le Bail @ 2014-02-11 14:06 UTC (permalink / raw)
To: NETDEV, David Miller
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 <fx.lebail@yahoo.com>
---
The diagnosis of cppcheck seems relevant.
net/core/rtnetlink.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 048dc8d..9a5dbf1 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -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));
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] net: rtnetlink: fix correct size given to memset
2014-02-11 14:06 [PATCH] net: rtnetlink: fix correct size given to memset Francois-Xavier Le Bail
@ 2014-02-11 15:28 ` Eric Dumazet
2014-02-11 15:54 ` David Laight
2014-02-11 16:01 ` François-Xavier Le Bail
0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2014-02-11 15:28 UTC (permalink / raw)
To: Francois-Xavier Le Bail; +Cc: NETDEV, David Miller
On Tue, 2014-02-11 at 15:06 +0100, Francois-Xavier Le Bail wrote:
> 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 <fx.lebail@yahoo.com>
> ---
>
> The diagnosis of cppcheck seems relevant.
>
> net/core/rtnetlink.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index 048dc8d..9a5dbf1 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -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.
^ permalink raw reply [flat|nested] 4+ messages in thread* RE: [PATCH] net: rtnetlink: fix correct size given to memset
2014-02-11 15:28 ` Eric Dumazet
@ 2014-02-11 15:54 ` David Laight
2014-02-11 16:01 ` François-Xavier Le Bail
1 sibling, 0 replies; 4+ messages in thread
From: David Laight @ 2014-02-11 15:54 UTC (permalink / raw)
To: 'Eric Dumazet', Francois-Xavier Le Bail; +Cc: NETDEV, David Miller
From: Eric Dumazet
> On Tue, 2014-02-11 at 15:06 +0100, Francois-Xavier Le Bail wrote:
> > 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 <fx.lebail@yahoo.com>
> > ---
> >
> > The diagnosis of cppcheck seems relevant.
> >
> > net/core/rtnetlink.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> > index 048dc8d..9a5dbf1 100644
> > --- a/net/core/rtnetlink.c
> > +++ b/net/core/rtnetlink.c
> > @@ -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.
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] net: rtnetlink: fix correct size given to memset
2014-02-11 15:28 ` Eric Dumazet
2014-02-11 15:54 ` David Laight
@ 2014-02-11 16:01 ` François-Xavier Le Bail
1 sibling, 0 replies; 4+ messages in thread
From: François-Xavier Le Bail @ 2014-02-11 16:01 UTC (permalink / raw)
To: Eric Dumazet; +Cc: NETDEV, David Miller
> From: Eric Dumazet <eric.dumazet@gmail.com>
> To: Francois-Xavier Le Bail <fx.lebail@yahoo.com>
>> 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 <fx.lebail@yahoo.com>
>> ---
>>
>> The diagnosis of cppcheck seems relevant.
>>
>> net/core/rtnetlink.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-02-11 16:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-11 14:06 [PATCH] net: rtnetlink: fix correct size given to memset Francois-Xavier Le Bail
2014-02-11 15:28 ` Eric Dumazet
2014-02-11 15:54 ` David Laight
2014-02-11 16:01 ` François-Xavier Le Bail
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox