Re: [PATCH 14/18] conf: Rework checking for garbage after a range

Stefano Brivio
2026-04-08T21:40:34Z

On Tue, 7 Apr 2026 13:16:26 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> After parsing port ranges conf_ports_spec() checks if we've reached a
> chunk delimiter (',') to verify that there isn't extra garbage there.
> Rework how we do this to use the recently introduces chunk-end pointer.

Nit: introduced

> This has two advantages:
>
> 1) Small, but practical: we don't need to repeat what the valid delimiters
> are, that's already handled in the chunk splitting code.
>
> 2) Large, if theoretical: this will also given an error if port parsing
> overruns a chunk boundary. We don't really expect that to happen, but
> it would give very confusing behaviour if it did. strtoul(3), on which
> parse_port_range() is based does say it may accept thousands separators
> based on locale which means can't entirely be sure it will only accept

Nit: we can't

> strings of digits.
>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> conf.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/conf.c b/conf.c
> index 1ab1b071..51612047 100644
> --- a/conf.c
> +++ b/conf.c
> @@ -264,7 +264,7 @@ static void conf_ports_spec(const struct ctx *c,
>
> if (parse_port_range(p, &p, &xrange))
> goto bad;
> - if ((*p != '\0') && (*p != ',')) /* Garbage after the range */
> + if (p != ep) /* Garbage after the range */
> goto bad;
>
> for (i = xrange.first; i <= xrange.last; i++)
> @@ -303,7 +303,7 @@ static void conf_ports_spec(const struct ctx *c,
> mapped_range = orig_range;
> }
>
> - if ((*p != '\0') && (*p != ',')) /* Garbage after the ranges */
> + if (p != ep) /* Garbage after the ranges */
> goto bad;
>
> if (orig_range.first == 0) {

--
Stefano