From: Stephen Hemminger <stephen@networkplumber.org>
To: Phil Sutter <phil@nwl.cc>
Cc: netdev@vger.kernel.org
Subject: Re: [iproute PATCH v2 7/7] lib/ll_map: Make sure im->name is NULL-terminated
Date: Fri, 18 Aug 2017 09:33:28 -0700 [thread overview]
Message-ID: <20170818093328.4d3eff55@xeon-e3> (raw)
In-Reply-To: <20170817170932.24659-8-phil@nwl.cc>
On Thu, 17 Aug 2017 19:09:32 +0200
Phil Sutter <phil@nwl.cc> wrote:
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> lib/ll_map.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/ll_map.c b/lib/ll_map.c
> index 4e4556c9ac80b..4d06eb69f138a 100644
> --- a/lib/ll_map.c
> +++ b/lib/ll_map.c
> @@ -120,11 +120,11 @@ int ll_remember_index(const struct sockaddr_nl *who,
> return 0;
> }
>
> - im = malloc(sizeof(*im));
> + im = calloc(1, sizeof(*im));
> if (im == NULL)
> return 0;
> im->index = ifi->ifi_index;
> - strcpy(im->name, ifname);
> + strncpy(im->name, ifname, IFNAMSIZ - 1);
> im->type = ifi->ifi_type;
> im->flags = ifi->ifi_flags;
>
This is not really necessary. kernel won't return
an ifname with a length >= IFNAMSIZ.
If you wanted to future proof it, why not use variable size allocation
--- a/lib/ll_map.c
+++ b/lib/ll_map.c
@@ -30,7 +30,7 @@ struct ll_cache {
unsigned flags;
unsigned index;
unsigned short type;
- char name[IFNAMSIZ];
+ char name[];
};
#define IDXMAP_SIZE 1024
@@ -120,7 +120,7 @@ int ll_remember_index(const struct sockaddr_nl *who,
return 0;
}
- im = malloc(sizeof(*im));
+ im = malloc(sizeof(*im) + strlen(ifname) + 1);
if (im == NULL)
return 0;
im->index = ifi->ifi_index;
prev parent reply other threads:[~2017-08-18 16:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-17 17:09 [iproute PATCH v2 0/7] Covscan: Fixes for string termination Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 1/7] ipntable: Make sure filter.name is NULL-terminated Phil Sutter
2017-08-18 9:19 ` David Laight
2017-08-18 10:52 ` Phil Sutter
2017-08-18 16:32 ` David Laight
2017-08-18 16:52 ` Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 2/7] xfrm_state: Make sure alg_name " Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 3/7] lib/fs: Fix format string in find_fs_mount() Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 4/7] lib/inet_proto: Make sure destination buffers are NULL-terminated Phil Sutter
2017-08-18 16:37 ` Stephen Hemminger
2017-08-18 16:55 ` Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 5/7] lnstat_util: Simplify alloc_and_open() a bit Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 6/7] tc/m_xt: Fix for potential string buffer overflows Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 7/7] lib/ll_map: Make sure im->name is NULL-terminated Phil Sutter
2017-08-18 16:33 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170818093328.4d3eff55@xeon-e3 \
--to=stephen@networkplumber.org \
--cc=netdev@vger.kernel.org \
--cc=phil@nwl.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.