Skip to content

hexstring truncation fixes

Stephen Hemminger netdev 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3utils: add hexstring_alloc and print_hexstring helpersinclude/json_print.h include/utils.h lib/json_print.c +1 more+37 -00 replies
2/3ip, tc: print hex attributes with print_hexstringip/ipaddress.c ip/ipmacsec.c lib/bpf_legacy.c +3 more+19 -390 replies
3/3tc: build ct label strings with hexstring_alloctc/f_flower.c tc/m_ct.c+28 -210 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH iproute2 0/3] hexstring truncation fixes

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(-)
Signature · 1 line
2.53.0