All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: Stephen Hemminger <stephen@networkplumber.org>, netdev@vger.kernel.org
Subject: Re: [PATCH iproute2-next 1/2] rt_names: parse name databases without sscanf
Date: Mon, 30 Nov 2026 10:27:21 -0700	[thread overview]
Message-ID: <f67eb7cd-a1af-4e61-9de8-83e10c0c4873@kernel.org> (raw)
In-Reply-To: <20261127165046.3656340-1-stephen@networkplumber.org>

On 11/27/26 9:50 AM, Stephen Hemminger wrote:
> fread_id_name() in rt_names.c and read_id_name() in names.c were the
> same reader, each trying a series of sscanf formats and reporting
> failure only when all of them missed. That hid several problems:
> 
>   - ids out of range were accepted after silent truncation, so
>     "0x100000000 foo" bound the name to table 0;
>   - ids above INT_MAX came back negative through "%d", and callers
>     discarded them as a bad id, making the upper half of the 32-bit
>     table id space unusable;
>   - the tc class handle halves in names.c were unbounded, so
>     "10000:1" shifted the major out of the id and bound the name to
>     handle 1:0;
>   - "%s" had no field width, safe only because the name buffer
>     happened to be as large as the line buffer.
> 
> Read the whole line, strip any comment and line ending, then parse it:
> strtoul() with an explicit base, a range check against UINT32_MAX, and
> a bounded copy of the name token. Negative ids are skipped as before,
> and text after the name is still ignored.
> 
> Put common code into get_db_entry() in lib/utils.c.
> The id parsing comes from the caller, so the "major:minor" form
> in tc can use same code.
> 
> The id is __u32 throughout, matching the kernel's table id width.
> Trailing carriage returns are dropped, so a database saved with CRLF
> line endings no longer yields names that match nothing.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  include/names.h |  7 ++++-
>  include/utils.h |  9 ++++++
>  lib/names.c     | 53 +++++++---------------------------
>  lib/rt_names.c  | 58 +++++++++++++-------------------------
>  lib/utils.c     | 75 +++++++++++++++++++++++++++++++++++++++++++++++++
>  tc/tc_util.c    | 33 ++++++++++++++++++++--
>  6 files changed, 150 insertions(+), 85 deletions(-)
> 

does not apply to top of tree for iproute2-next


      parent reply	other threads:[~2026-11-30 17:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 16:50 [PATCH iproute2-next 1/2] rt_names: parse name databases without sscanf Stephen Hemminger
2026-11-27 16:50 ` [PATCH iproute2-next 2/2] lib: use flex array for names Stephen Hemminger
2026-11-30 17:27 ` David Ahern [this message]

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=f67eb7cd-a1af-4e61-9de8-83e10c0c4873@kernel.org \
    --to=dsahern@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.