🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24714

Re: [PATCH iproute2-next 1/2] rt_names: parse name databases without sscanf

#24714
From: David Ahern
Date: Mon, 30 Nov 2026 17:27
42 lines
9470 bytes
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
Technical Details
Message-ID: <f67eb7cd-a1af-4e61-9de8-83e10c0c4873@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374345-linux-kernel-netdev=dewy.ru
References: <20261127165046.3656340-1-stephen@networkplumber.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374345-linux-kernel-netdev=dewy.ru
From: dsahern@kernel.org (David Ahern)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH iproute2-next 1/2] rt_names: parse name databases without
 sscanf
Date: Mon, 30 Nov 2026 10:27:21 -0700
Organization: Usenet Network
Message-ID: <f67eb7cd-a1af-4e61-9de8-83e10c0c4873@kernel.org>
References: <20261127165046.3656340-1-stephen@networkplumber.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1484805"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:KQ9IIWEJQMHWz41LaFpKS8jLBDU= sha256:zZokHnNn5PF126c9kfXsnejerJZJQ0fd7792iMYbGbY=
	sha1:QUwogHJSHVRnIRkxz7ShBWiXJrA= sha256:iRaBJH1CA3hLJ/PFlJyEwJP5pd8Gb5qUj2PcnDDSdSE=
Content-Language: en-US
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9D8FA125FFA; Mon, 30 Nov 2026 20:27:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id tXUOBNTbf5hV;
	Mon, 30 Nov 2026 20:27:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-374345-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 5C4F1125FF8; Mon, 30 Nov 2026 20:27:27 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 1C1E4601ADF; Mon, 30 Nov 2026 17:27:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796059643;
	b=BEWzYpTHFukoyj5JVJ6fRKWQpsGD10G03hec1i4ES7HwI7tMcWY/5Wg9p9WmCEdxv/dB
	 R3sRw/1uS8MGTFHsoBuascfGPhK/yP8ST1UI5wd7pPLB/9wxVIZb8P1oknLTtCkplQsfC
	 d2gpODP0wRuYzDaW0m0p2WCRCQA2b1KC17qbztxEO705tOymRXu4cjC2+F8CLtRE+mwO6
	 4kg+8F+1gELEx9yqXRSz3iudLS7s0bPnO+3KT5KkbxTR7XqyKKXP9fmJbqvUIRhyWa/0+
	 yrscMkpOfHXVULYJ3rn7YwrBqIwuk8cuTHz0Br3asjRPkyYKr/7t2RQswWEX6G9GjuA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796059643;
	h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:To:References:Content-Language:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=999fGePVduA6otpn1FY/mKZzdprfHwLA6XieGUvJjPY=;
	b=2iUYKoq49gLHBYcAofKLqShYjP8feIsz8mXBcUSRucArhdsDOx3NQK6xq6x6WhQ22nvc
	 XbuBeKjKtR63jmGnjDXsiYSP0b8mtQ4qiuhIUO+TbDIq9ErIdL2TbvtdyiRxfGTUyGbrl
	 jmh07Z93lYxqaLMaB0PKV3AONJYz7hseUYqAU9LrQqvDckd9ivQ63xH+WMpQYSaiET26H
	 sJ5HfVUoUnMntspz7Qna1TfQ+VllKXfLSXS9Ix8Q1LaixmkxSC4WZ+MMUMhC/VGJVRobT
	 FRlkMyFvq4HanQFCFmqD1nxZ0Sf7lZCM9tANQJ/a2VabaUwP4x2KtX8AFDjpZKuDWPg==
X-ARC-Authentication-Results: i=2; 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=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 57857606A6A9;
	Mon, 30 Nov 2026 17:27:23 +0000 (UTC)
X-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
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-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==
X-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==
X-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
X-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 <netdev@vger.kernel.org>; Mon, 30 Nov 2026 17:27:22 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A4F91F00897;
	Mon, 30 Nov 2026 17:27:22 +0000 (UTC)
X-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==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-In-Reply-To: <20261127165046.3656340-1-stephen@networkplumber.org>