netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Jeremy Sowden <jeremy@azazel.net>
Cc: Netfilter Devel <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nft] scanner: treat invalid octal strings as strings
Date: Thu, 22 Dec 2022 11:38:35 +0100	[thread overview]
Message-ID: <Y6Qzq48e+ihIf4La@salvia> (raw)
In-Reply-To: <20221216202714.1413699-1-jeremy@azazel.net>

Hi Jeremy,

On Fri, Dec 16, 2022 at 08:27:14PM +0000, Jeremy Sowden wrote:
> The action associated with the `{numberstring}` pattern, passes `yytext`
> to `strtoull` with base 0:
> 
> 	errno = 0;
> 	yylval->val = strtoull(yytext, NULL, 0);
> 	if (errno != 0) {
> 		yylval->string = xstrdup(yytext);
> 		return STRING;
> 	}
> 	return NUM;
> 
> If `yytext` begins with '0', it will be parsed as octal.  However, this
> has unexpected consequences if the token contains non-octal characters.
> `09` will be parsed as 0; `0308` will be parsed as 24, because
> `strtoull` and its siblings stop parsing as soon as they reach a
> character in the input which is not valid for the base.
> 
> Replace the `{numberstring}` match with separate `{hexstring}` and
> `{decstring}` matches.  For `{decstring}` set the base to 8 if the
> leading character is '0', and handle an incompletely parsed token in
> the same way as one that causes `strtoull` to set `errno`.
> 
> Thus, instead of:
> 
>   $ sudo nft -f - <<<'
>     table x {
>       chain y {
>         ip saddr 0308 continue comment "parsed as 0.0.0.24/32"
>       }
>     }
>   '
>   $ sudo nft list chain x y
>   table ip x {
>     chain y {
>       ip saddr 0.0.0.24 continue comment "parsed as 0.0.0.24/32"
>     }
>   }
> 
> We get:
> 
>   $ sudo ./src/nft -f - <<<'
>   > table x {
>   >   chain y {
>   >     ip saddr 0308 continue comment "error"
>   >   }
>   > }
>   > '
>   /dev/stdin:4:14-17: Error: Could not resolve hostname: Name or service not known
>       ip saddr 0308 continue comment "error"
>                ^^^^
> 
> Add a test-case.

Applied, thanks.

I am sorry I missed this patch before the release.

  reply	other threads:[~2022-12-22 10:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 20:27 [PATCH nft] scanner: treat invalid octal strings as strings Jeremy Sowden
2022-12-22 10:38 ` Pablo Neira Ayuso [this message]
2022-12-22 10:52   ` Pablo Neira Ayuso
2022-12-22 11:02     ` Jeremy Sowden
2022-12-22 11:23       ` Pablo Neira Ayuso

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=Y6Qzq48e+ihIf4La@salvia \
    --to=pablo@netfilter.org \
    --cc=jeremy@azazel.net \
    --cc=netfilter-devel@vger.kernel.org \
    /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).