print_string_name_value() and print_uint_name_value() snprintf'd the caller's name into a 64-byte buffer and used it as the printf format, so a '%' in the name was taken as a conversion and names over 63 bytes lost their value to truncation. Pass the name as a string argument with a literal format instead. Fixes: 31ca29b2bec4 ("json_print: Introduce print_#type_name_value") Reported-by: Anthropic OSS scanner Assiste-By: Claude:claude-opus-5-5 Signed-off-by: Stephen Hemminger --- lib/json_print.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/json_print.c b/lib/json_print.c index f604f265..e028e766 100644 --- a/lib/json_print.c +++ b/lib/json_print.c @@ -147,11 +147,8 @@ _PRINT_FUNC(float, double); #define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char) \ void print_##type_name##_name_value(const char *name, type value)\ { \ - SPRINT_BUF(format); \ - \ - snprintf(format, SPRINT_BSIZE, \ - "%s %%"#format_char, name); \ - print_##type_name(PRINT_ANY, name, format, value); \ + print_string(PRINT_FP, NULL, "%s ", name); \ + print_##type_name(PRINT_ANY, name, "%"#format_char, value); \ } _PRINT_NAME_VALUE_FUNC(uint, unsigned int, u); _PRINT_NAME_VALUE_FUNC(string, const char*, s); -- 2.53.0