Netdev List
 help / color / mirror / Atom feed
* [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
@ 2026-11-10  3:39 Jingjing Xu
  2026-11-10  6:37 ` Hangbin Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jingjing Xu @ 2026-11-10  3:39 UTC (permalink / raw)
  To: donald.hunter, kuba; +Cc: netdev

Netlink strings are not restricted to ASCII. A valid non-ASCII interface
name makes a getlink dump fail with UnicodeDecodeError, and encoding
such a name for a rename request raises UnicodeEncodeError.

Use UTF-8 with surrogateescape for both directions. This preserves ASCII
behavior, handles UTF-8 names and round-trips raw non-UTF-8 bytes that
Linux also permits in interface names. Do not replace invalid bytes and
lose the original name.

Discovered by Codex-assisted code inspection and reproduced using real
rtnetlink operations in a temporary network namespace. Tested ASCII
names, a UTF-8 name and a name containing byte 0xff in link dumps, plus
UTF-8 and non-UTF-8 rename requests. The original library fails on the
non-ASCII inputs; the fixed library reads and writes the names without
losing bytes. Python byte compilation passes. No kernel instrumentation
or hardware was needed.

Fixes: e4b48ed460d3 ("tools: ynl: add a completely generic client")
Signed-off-by: Jingjing Xu <xujingjing@cmss.chinamobile.com>
---
 tools/net/ynl/pyynl/lib/ynl.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index fb5acb8acded..2402d7c383e7 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -301,7 +301,7 @@ class NlAttr:
         return format_.unpack(self.raw)[0]
 
     def as_strz(self):
-        return self.raw.decode('ascii')[:-1]
+        return self.raw.decode('utf-8', 'surrogateescape')[:-1]
 
     def as_bin(self):
         return self.raw
@@ -852,7 +852,7 @@ class YnlFamily(SpecFamily):
                 return b''
             attr_payload = b''
         elif attr["type"] == 'string':
-            attr_payload = str(value).encode('ascii') + b'\x00'
+            attr_payload = str(value).encode('utf-8', 'surrogateescape') + b'\x00'
         elif attr["type"] == 'binary':
             if value is None:
                 attr_payload = b''
base-commit: 1d5e2c57e9ffc134e14b3f837c8d7c53b508bd22
-- 
2.53.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-10 18:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10  3:39 [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes Jingjing Xu
2026-11-10  6:37 ` Hangbin Liu
2026-11-10 11:50 ` Xia Yan
2026-11-10 18:58 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox