From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796059642; b=q6Y9tNjUoNFHrY3UQ3x5AKR/N7UGeZE+gRGs8HKwEcJ5js+fGKzNFLUMc6u96FSzwNSJ XthQLc4eSpt7OGYi9P5DU2IM4nCeXkrm+BuDqu7oUx1pCJBxwoJRzV7A3aHB/gzLV93Z7 4rbU9LGrp1+t451K5eW5P8mczdh1TeBHHjmmJJj/w1NEH4wqXueWvPnct3W3rJz3BpAT/ zznczxBCJ0nLKR52Q2NMyp+47lyRuHrUltM5THus/6yXpo1QKO33+3QdAGp1cGZOl2v5X 6UFpmEvegf/DRD9X+b4HbBOiLlVpKfy2H+nETzVix01g3w6cAPfDvz5uu86N+dti6Lw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796059642; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=999fGePVduA6otpn1FY/mKZzdprfHwLA6XieGUvJjPY=; b=s8eDrDOEuGqNcDkO8R4FWNskkw9Otoj2s2yYCDcAunBBEeACtVvgnep1HmNT7Q86Eh3m b/uEbwN4XzquNgN0RhD875LD33lEKaghGeB/wiNalB1eeG2skKV0HR+tHA9m1HOiBz7eu RD7feOAnEcbRSrCGFCPG8T7LTK/WfUXJVfw8WgeMa3HssdnNjIEjULIG7JZZ7IM8EaNsN zoQ1h7tOXPHQa6x0cV2r95CnPG7AVD6YnbwWf6V3LF0DgNo67DaKIIfQoSFw0o+w/Dcb4 na+lov1HlvXdMihRI1K5N9ZG3OLM1TXqUowwsf78dfVYPpZufiLjN0w9WQyqNWZLVJw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LzV+2yi8; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A2C6606A697 for ; Mon, 30 Nov 2026 17:27:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LzV+2yi8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A4F91F00897; Mon, 30 Nov 2026 17:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796059642; bh=999fGePVduA6otpn1FY/mKZzdprfHwLA6XieGUvJjPY=; h=Date:Subject:To:References:From:In-Reply-To; b=LzV+2yi8D3X9FViTa1bxqE+vDHWzTf/HigzvDpYTe87u9F91njUqIBFhX8Sdg7qtG nGm4EV5COuCriDhh2BvcFP9vJnbV69JeQ65Qo8ac5v4vbx+eTjTXXDXgC3zjDd1KCH XqvvWlCr3tsEAxHtGMmpJuftTg4RFMlhDo3VXGz2SmClQ7NUeVMw7kP/99Zqyg+rrP UR1fV068aBDdbhBqm9KL+FExOxQr57iNEKgGviD/Zy25FxsxP/mKJwl7wo5uOBMwJ+ kGT134YYCbCpkYDgKaBlUOc+hQLDpqIdfJFpNvmVdkumPvwVqDlTociTdFxT8xtgNT skQ2Ew6BgGAcw== Message-ID: Date: Mon, 30 Nov 2026 10:27:21 -0700 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH iproute2-next 1/2] rt_names: parse name databases without sscanf To: Stephen Hemminger , netdev@vger.kernel.org References: <20261127165046.3656340-1-stephen@networkplumber.org> Content-Language: en-US From: David Ahern In-Reply-To: <20261127165046.3656340-1-stephen@networkplumber.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > --- > 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