json_print: Add explicit condition in print_color_string()
Subsystems (3)
PATCH 1/1 json_print: Add explicit condition in print_color_string()
Added explicit condition for check key and value in print_color_string() to avoid call jsonw_string_field with key=NULL and value=NULL.
Signed-off-by Maks Mishin <[email protected]>
--- lib/json_print.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/json_print.c +1 -1
@@ -170,7 +170,7 @@ int print_color_string(enum output_type type,jsonw_name (_jw, key); else if (!key && value)jsonw_string (_jw, value); - else + else if (key && value) jsonw_string_field(_jw, key, value); }else if (_IS_FP_CONTEXT (type)) { ret =color_fprintf (stdout, color, fmt, value);
Signature · 1 line
2.30.2
Quoted 5 lines · On Tue, 13 Feb 2024 23:40:09 +0300 Maks Mishin <[email protected]> wrote:
Added explicit condition for check
keyandvalueinprint_color_string()to avoid calljsonw_string_fieldwith key=NULL and value=NULL.Signed-off-by Maks Mishin <[email protected]>
Thanks for the patch, but looks like another potential issue found by a checker. Anything calling print_color_string and wanting to print a json string with key and value of NULL is broken. This change would paper over a real bug.
Do you have a test case where this occurs?