hexstring truncation fixes
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | utils: add hexstring_alloc and print_hexstring helpersinclude/ include/ lib/ +1 more | +37 | 0 replies | |
| 2/3 | ip, tc: print hex attributes with print_hexstringip/ ip/ lib/ +3 more | +19 | 0 replies | |
| 3/3 | tc: build ct label strings with hexstring_alloctc/ tc/ | +28 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
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