netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: netdev@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH] iproute2: ip maddress: Check multiaddr length
Date: Fri, 14 Aug 2020 08:27:56 -0700	[thread overview]
Message-ID: <20200814082756.18888961@hermes.lan> (raw)
In-Reply-To: <20200814084626.22953-1-s.hauer@pengutronix.de>

On Fri, 14 Aug 2020 10:46:26 +0200
Sascha Hauer <s.hauer@pengutronix.de> wrote:

> ip maddress add|del takes a MAC address as argument, so insist on
> getting a length of ETH_ALEN bytes. This makes sure the passed argument
> is actually a MAC address and especially not an IPv4 address which
> was previously accepted and silently taken as a MAC address.
> 
> While at it, do not print *argv in the error path as this has been
> modified by ll_addr_a2n() and doesn't contain the full string anymore,
> which can lead to misleading error messages.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  ip/ipmaddr.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
> index 3400e055..9979ed58 100644
> --- a/ip/ipmaddr.c
> +++ b/ip/ipmaddr.c
> @@ -291,7 +291,7 @@ static int multiaddr_modify(int cmd, int argc, char **argv)
>  {
>  	struct ifreq ifr = {};
>  	int family;
> -	int fd;
> +	int fd, len;
>  
>  	if (cmd == RTM_NEWADDR)
>  		cmd = SIOCADDMULTI;
> @@ -313,9 +313,12 @@ static int multiaddr_modify(int cmd, int argc, char **argv)
>  				usage();
>  			if (ifr.ifr_hwaddr.sa_data[0])
>  				duparg("address", *argv);
> -			if (ll_addr_a2n(ifr.ifr_hwaddr.sa_data,
> -					14, *argv) < 0) {
> -				fprintf(stderr, "Error: \"%s\" is not a legal ll address.\n", *argv);
> +			len = ll_addr_a2n(ifr.ifr_hwaddr.sa_data, 14, *argv);

While you are at it, get rid of the hard code 14 here and use sizeof(ifr.ifr_hwaddr.sa_data)?

  reply	other threads:[~2020-08-14 15:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14  8:46 [PATCH] iproute2: ip maddress: Check multiaddr length Sascha Hauer
2020-08-14 15:27 ` Stephen Hemminger [this message]
2020-08-17 11:25   ` Sascha Hauer

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=20200814082756.18888961@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=kernel@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    /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).