Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2 0/3] hexstring truncation fixes
@ 2026-07-23 19:11 Stephen Hemminger
  2026-07-23 19:11 ` [PATCH iproute2 1/3] utils: add hexstring_alloc and print_hexstring helpers Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stephen Hemminger @ 2026-07-23 19:11 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

This is an alternative to Gris Ge's "Fix netdevsim switch_id display
truncation", which bumped SPRINT_BSIZE from 64 to 128.

hexstring_n2a() writes into a caller buffer and silently truncates when
it is too small: the loop stops once fewer than three bytes remain and
returns the partial string. A 32-byte netdevsim switch id needs 65
bytes but SPRINT_BUF is 64, so "ip -d link show" printed only 62 of the
64 hex characters. Bumping SPRINT_BSIZE hides this one case but leaves
the truncation in place for the next key wider than the buffer, and
enlarges every unrelated SPRINT_BUF on the stack.

Fix the class of bug instead. Add hexstring_alloc(), which sizes the
output to the input, and print_hexstring(), a wrapper over print_string()
that formats and prints a binary attribute with no caller buffer. Move
the print-and-truncate sites onto it, and rebuild the ct label strings,
which open-coded pointer math into a fixed buffer, with hexstring_alloc()
and asprintf().

Stephen Hemminger (3):
  utils: add hexstring_alloc and print_hexstring helpers
  ip, tc: print hex attributes with print_hexstring
  tc: build ct label strings with hexstring_alloc

 include/json_print.h |  3 +++
 include/utils.h      |  1 +
 ip/ipaddress.c       | 19 ++++++-------------
 ip/ipmacsec.c        |  7 ++-----
 lib/bpf_legacy.c     |  6 ++----
 lib/json_print.c     | 12 ++++++++++++
 lib/utils.c          | 21 +++++++++++++++++++++
 tc/f_bpf.c           |  8 +++-----
 tc/f_flower.c        | 25 ++++++++++++++-----------
 tc/m_action.c        |  9 +++------
 tc/m_bpf.c           |  9 +++------
 tc/m_ct.c            | 24 ++++++++++++++----------
 12 files changed, 84 insertions(+), 60 deletions(-)

-- 
2.53.0


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

end of thread, other threads:[~2026-07-23 19:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 19:11 [PATCH iproute2 0/3] hexstring truncation fixes Stephen Hemminger
2026-07-23 19:11 ` [PATCH iproute2 1/3] utils: add hexstring_alloc and print_hexstring helpers Stephen Hemminger
2026-07-23 19:11 ` [PATCH iproute2 2/3] ip, tc: print hex attributes with print_hexstring Stephen Hemminger
2026-07-23 19:11 ` [PATCH iproute2 3/3] tc: build ct label strings with hexstring_alloc Stephen Hemminger

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