๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13893

Re: [PATCH v4 1/2] lib/net_utils: allow mac_pton() to take a custom delimiter

#13893
From: netdev-bot+sashiko
Date: Tue, 10 Nov 2026 12:54
79 lines
10876 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The kernel-doc this patch adds for parse_mac_pton() in
  lib/net_utils.c does not match what the function does.

--

lib/net_utils: allow mac_pton() to take a custom delimiter

This commit moves the body of mac_pton() into a new parse_mac_pton(),
which takes a string of accepted separator characters. mac_pton()
becomes a static inline wrapper that passes ":", so existing callers
behave as before.

Link: https://lore.kernel.org/all/20261105072147.3383565-2-liuc63@xiaopeng.com/

> diff --git a/lib/net_utils.c b/lib/net_utils.c
> index 215cda672fee1..011857cc978b4 100644
> --- a/lib/net_utils.c
> +++ b/lib/net_utils.c
> @@ -5,7 +5,18 @@
>  #include <linux/export.h>
>  #include <linux/hex.h>
>  
> -bool mac_pton(const char *s, u8 *mac)
> +/**
> + * parse_mac_pton - convert a MAC address string using a custom delimiter
> + * @s: string to be parsed
> + * @mac: buffer to store the result, left untouched if @s is malformed
> + * @delim: characters accepted as a separator between the byte pairs
> + *
> + * @s must be MAC_ADDR_STR_LEN characters long and use a character from
> + * @delim at every separator position, e.g. "aa.bb:cc.dd:ee.ff" with ".:".
> + *
> + * Return: true on success, false if @s is malformed.
> + */

[Severity: Low]
This isn't a bug, but does this kernel-doc describe what parse_mac_pton()
actually does?

The only length check in the function is:

	if (strnlen(s, MAC_ADDR_STR_LEN) < MAC_ADDR_STR_LEN)
		return false;

strnlen() is capped at MAC_ADDR_STR_LEN, so this check only rejects
strings that are too short. The parsing loops read only s[0] through
s[16], and nothing checks that s[MAC_ADDR_STR_LEN] is '\0'.

So input such as "aa:bb:cc:dd:ee:ffJUNK", or the 7-octet
"aa:bb:cc:dd:ee:ff:00", returns true and fills @mac with the first six
octets. That doesn't fit "@s must be MAC_ADDR_STR_LEN characters long"
or "false if @s is malformed".

The runtime behaviour is the same as the old mac_pton(). The current
callers (the mac_pton() wrapper, and get_ether_addr() in u_ether.c later
in this series) don't depend on long strings being rejected. However, a
new caller that trusts this doc could skip its own end-of-string check.

Could the doc say instead that @s must have at least MAC_ADDR_STR_LEN
characters and that anything after them is ignored? The other option is
to reject strings where s[MAC_ADDR_STR_LEN] != '\0', but that would
change behaviour for existing mac_pton() callers.

> +bool parse_mac_pton(const char *s, u8 *mac, const char *delim)
>  {
>  	int i;
>  

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106030605.576584-1-liuc63%40xiaopeng.com
Technical Details
Message-ID: <179431528628.994134.9205744622940373491@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360198-linux-kernel-netdev=dewy.ru
References: <20261106030605.576584-2-liuc63@xiaopeng.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360198-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v4 1/2] lib/net_utils: allow mac_pton() to take a custom delimiter
Date: Tue, 10 Nov 2026 12:54:46 +0000
Organization: Usenet Network
Message-ID: <179431528628.994134.9205744622940373491@kernel.org>
References: <20261106030605.576584-2-liuc63@xiaopeng.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="610076"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7L3z3cUDXwPKcZrhOybNR0N5ao0= sha256:adUQFyVdHTGHiJ2AwqKOstlgNwysgxv3chcYrVEQ6XA=
	sha1:qSrzKvC2C2WZQ0e+s12hCt7fatU= sha256:coPt+O5FiZJmAADQQLXs0s32kbpOCDaYwq5g71S/Va0=
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 02DA8113B8C; Tue, 10 Nov 2026 16:02:17 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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, URIBL_BLOCKED=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 zqS6T0hLZ2I2;
	Tue, 10 Nov 2026 16:02:13 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-360198-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 121C4113B84; Tue, 10 Nov 2026 16:01:58 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 3C198105CAA; Tue, 10 Nov 2026 12:55:17 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1794315294;
	b=iLjUYjkkjFINgAb6H4D4YaeakKL5HiSqAgPdA1AzvDhEp0c3kpj9kzQlmocJ9L6Jr2yt
	 NkAMdY5Zflc9gfE8PZqeEj0/98vKhkNTvGgASZWMYrG7PbU/nOFuP8mZAOvNzMjxhOi+8
	 ss/o68BAuZQzg6/ZfoGFy1BKUmjsm3+f/nwb2zidmtfxGIgDncRfUdKOqHHknxrh3axAA
	 tt+ZERgsTBELmCYok8RXkGL+za6L5QPDisHVoY3k2MdVbkL6LZz1v2BMAU6X19e8s/3yg
	 g060JV1PaJAMoXTs2qx274nY+a6LyCNqIMpK7VsXUACNAPo/jTgcWm3FVLhyc6JpV4w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794315294;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=1+2k5LckoMlRz1UsGVfXPTvJfkXcF184agG+LHhQ6uI=;
	b=pJTVbHvBY3DOxo8MICZxyxU6vFojiLFzyNS4mnvJi/O3XYAllrzSf5KJ/2isWuGq6wpb
	 PfVgbX+pbMqVWGuSYbqsmdoAd6zah+JYU6Iqk4i2qjCoZJykRzNAwsHfKzbsFIGnIXv8z
	 nMX+0pOZoHfR+FOoMcERk27QkNd0lopnPTgSY/6LafKP5OcTWXD27H7kchFKDa5RBGNxV
	 0hDVb5yaZnOMv+tioVH7qtQEDWf9XIQZoPmSKR2VKqSRCwNfpeIhwqhJvpxdqvoywuhxy
	 lLzLcXZMeqWHQ3+uqN/TjYp1Ai5G6BWDgrfFhD29q77OA/cz1rz00BcIa2u2mo/Qc/g==
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="f/zSVM8/";
	arc=fail 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 1651060A2603;
	Tue, 10 Nov 2026 12:54:54 +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=f/zSVM8/
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=1794315288;
	b=Q/cNuOcqBaV+9k8PD1eblK37GR8q9DsgLuBRsIuWwhbRa0P+ZDm+MSJDIuWjqWW9RCgw
	 0NjrpdwPtB63p3+VQtY+yZY8bn7itHttbuadaNjD3DL6OMwTwiOkrKXH8uFKBMe9uVt98
	 W2j/1REcYq3dsFJTefia8fMEG8wsTCl4ZCCHq4J8mc7qubbz8ZHCpmKYJSJhSHWDH4KmU
	 HoDnrRFzdnvILgKxpqxWRKOn+WoBSdiiqWF/bt7cJxzE+XB5mzHb9fPzt7mNHCspgvSpY
	 JecYWNkQ2VxiCK+9wQxaaS3912ceZ+c3yov0+CDRKXq1A3hyseDyWS3ozOoIGRdbsOg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794315288;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=1+2k5LckoMlRz1UsGVfXPTvJfkXcF184agG+LHhQ6uI=;
	b=elMIeUoLsCm+wGFifJcBh3aYOEFYtyz1hXZJObi7gzgUAE6/YCr/4h8OP8cKgdk2xoWl
	 e/xmu5QzMGi21cVdUENa/D5Zr1zS7VyXQAmzkOl9fY+me57/8KIvnJpEPji7c9CkKAOqY
	 VbqIaz9cuZB5qzfQi15br59/7doKi2XYnV/JzA98OGxeNxq7Q76xaxuK7jJSQ4yVeiHsi
	 YZG/lKkeo+enzJoBJhnvpb9rRo4dI7h9ZvP24PxlHYkjHn1Aw9/wYyWS1H913Wpfg28+e
	 KKdzQq5EaUg9WJNokDLn8AWiEuyyodY7vDl5DAUzljlcnlGw7CFGytkkv2NKs5v2DuQ==
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="f/zSVM8/";
	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 E3464606A336;
	Tue, 10 Nov 2026 12:54:47 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7F5D1F008A2;
	Tue, 10 Nov 2026 12:54:46 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794315287;
	bh=1+2k5LckoMlRz1UsGVfXPTvJfkXcF184agG+LHhQ6uI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=f/zSVM8/aG5/mr1KV04vTH9V5U8+FsOb/Jzgzli3GSTfjY2Ch1qqMEg0reZipXUvj
	 I5DWAFQMn/iYdo+zlXIveCaSxSkK2TKCLj9RGnH06zCE6QByvF9mKIdKdkvKRSuZEx
	 sxMfN2kUl9ndSIn3jl3m0taYiDibWw5YHu1bwzgPoFRFXXdR+e+JyOg9JT4qUr76HR
	 DkZGYcGE+n9yPol4hB7iM676ji6+LgDFd/s+KiArvaYW3DNh1fdXjhAbPP1kt8x/Nr
	 DrLnwR+JO48GaFQ9lEcK0WnqGVwrkFJLEnMge8Jq+WnlX28iespYtHCM2yigBF28Z0
	 99sHnlDcJMeyA==
X-Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org,
 andriy.shevchenko@intel.com, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, khtsai@google.com,
 fangxy@xiaopeng.com, rdunlap@infradead.org, dbrownell@users.sourceforge.net,
 linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
 netdev@vger.kernel.org
X-In-Reply-To: <20261106030605.576584-2-liuc63@xiaopeng.com>
X-sashiko-severity: Low
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