Skip to contentSkip to conversation

json_print: Add explicit condition in print_color_string()

PATCH In review Maks Mishin 2 participants 2 messages Feb 13, 2024 – Feb 15, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

---
 lib/json_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/json_print.c +1 -1
index 810d496e..a264614c 100644
@@ -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
#1 lore raw
Quoted 5 lines · On Tue, 13 Feb 2024 23:40:09 +0300 Maks Mishin <[email protected]> wrote:

Added explicit condition for check key and value in print_color_string() to avoid call jsonw_string_field with key=NULL and value=NULL.

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?