Netdev List
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2 0/3] hexstring truncation fixes
Date: Thu, 23 Jul 2026 12:11:37 -0700	[thread overview]
Message-ID: <20260723191511.216182-1-stephen@networkplumber.org> (raw)

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


             reply	other threads:[~2026-07-23 19:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 19:11 Stephen Hemminger [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260723191511.216182-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox