From: Stephen Hemminger <stephen@networkplumber.org>
To: Phil Sutter <phil@nwl.cc>
Cc: netdev@vger.kernel.org
Subject: Re: [iproute PATCH v3 6/6] lib/libnetlink: Don't pass NULL parameter to memcpy()
Date: Thu, 24 Aug 2017 15:29:43 -0700 [thread overview]
Message-ID: <20170824152943.17173f52@xeon-e3> (raw)
In-Reply-To: <20170824094131.2963-7-phil@nwl.cc>
On Thu, 24 Aug 2017 11:41:31 +0200
Phil Sutter <phil@nwl.cc> wrote:
> Both addattr_l() and rta_addattr_l() may be called with NULL data
> pointer and 0 alen parameters. Avoid calling memcpy() in that case.
>
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> lib/libnetlink.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/libnetlink.c b/lib/libnetlink.c
> index 874e660be7eb4..fbe719ee10449 100644
> --- a/lib/libnetlink.c
> +++ b/lib/libnetlink.c
> @@ -871,7 +871,8 @@ int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
> rta = NLMSG_TAIL(n);
> rta->rta_type = type;
> rta->rta_len = len;
> - memcpy(RTA_DATA(rta), data, alen);
> + if (alen)
> + memcpy(RTA_DATA(rta), data, alen);
> n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len);
> return 0;
> }
> @@ -958,7 +959,8 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
> subrta = (struct rtattr *)(((char *)rta) + RTA_ALIGN(rta->rta_len));
> subrta->rta_type = type;
> subrta->rta_len = len;
> - memcpy(RTA_DATA(subrta), data, alen);
> + if (alen)
> + memcpy(RTA_DATA(subrta), data, alen);
> rta->rta_len = NLMSG_ALIGN(rta->rta_len) + RTA_ALIGN(len);
> return 0;
> }
Ok, applied. You never know when GCC language experts might decide
to exploit undefined behavior.
next prev parent reply other threads:[~2017-08-24 22:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-24 9:41 [iproute PATCH v3 0/6] Covscan: Misc fixes Phil Sutter
2017-08-24 9:41 ` [iproute PATCH v3 1/6] ss: Make struct tcpstat fields 'timer' and 'timeout' unsigned Phil Sutter
2017-08-24 9:41 ` [iproute PATCH v3 2/6] ss: Make sure scanned index value to unix_state_map is sane Phil Sutter
2017-08-24 9:41 ` [iproute PATCH v3 3/6] netem/maketable: Check return value of fscanf() Phil Sutter
2017-08-24 9:41 ` [iproute PATCH v3 4/6] lib/bpf: Check return value of write() Phil Sutter
2017-08-24 9:41 ` [iproute PATCH v3 5/6] lib/fs: Fix and simplify make_path() Phil Sutter
2017-08-24 9:41 ` [iproute PATCH v3 6/6] lib/libnetlink: Don't pass NULL parameter to memcpy() Phil Sutter
2017-08-24 22:29 ` Stephen Hemminger [this message]
2017-08-24 22:30 ` [iproute PATCH v3 0/6] Covscan: Misc fixes Stephen Hemminger
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=20170824152943.17173f52@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 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).