netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@redhat.com>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: netdev@vger.kernel.org
Subject: Re: [RFC] iproute2: Fix meta match u32 with 0xffffffff
Date: Tue, 12 Apr 2011 09:56:49 +0200	[thread overview]
Message-ID: <1302595009.3664.8.camel@lsx> (raw)
In-Reply-To: <20110411115234.74b5936b@nehalam>

On Mon, 2011-04-11 at 11:52 -0700, Stephen Hemminger wrote: 
> The value 0xffffffff is a valid mask and bstrtoul() would return
> ULONG_MAX which was the error value. Resolve the problem by separating
> return value and error indication.
>  
> -unsigned long bstrtoul(const struct bstr *b)
> +int bstrtoul(const struct bstr *b, unsigned long *lp)
>  {
>  	char *inv = NULL;
> -	unsigned long l;
>  	char buf[b->len+1];
>  
> +	if (b->len == 0)
> +		return -EINVAL;
> +
>  	memcpy(buf, b->data, b->len);
>  	buf[b->len] = '\0';
>  
> -	l = strtoul(buf, &inv, 0);
> -	if (l == ULONG_MAX || inv == buf)
> -		return ULONG_MAX;
> +	*lp = strtoul(buf, &inv, 0);
> +	if (inv == buf)
> +		return -EINVAL;
> +
> +	if (*lp == ULONG_MAX || errno == ERANGE)
> +		return -ERANGE;
>  
> -	return l;
> +	return 0;
>  }

This is definitely much better but we still can't parse ULONG_MAX
as string representative. Checking glibc docs, the only way to do it is
to ignore the return value for error checking and look errno.

So I guess we should do something like this:

errno = 0;
*lp = strtoul(buf, &inv, 0);
if (*inv != '\0')
return -EINVAL;
else if (errno)
return errno;

return 0;


  reply	other threads:[~2011-04-12  7:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 18:52 [RFC] iproute2: Fix meta match u32 with 0xffffffff Stephen Hemminger
2011-04-12  7:56 ` Thomas Graf [this message]
2011-04-12 15:19   ` Stephen Hemminger
2011-04-12 17:22     ` Thomas Graf
2011-04-12 17:31       ` 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=1302595009.3664.8.camel@lsx \
    --to=tgraf@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    /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).