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 <step…@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