[PATCH iproute2 0/3] hexstring truncation fixes
From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2026-07-23 19:15:17
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