netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] json_print: Add explicit condition in print_color_string()
@ 2024-02-13 20:40 Maks Mishin
  2024-02-15  3:00 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Maks Mishin @ 2024-02-13 20:40 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Maks Mishin, netdev

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 <maks.mishinFZ@gmail.com>
---
 lib/json_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/json_print.c b/lib/json_print.c
index 810d496e..a264614c 100644
--- a/lib/json_print.c
+++ b/lib/json_print.c
@@ -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);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] json_print: Add explicit condition in print_color_string()
  2024-02-13 20:40 [PATCH] json_print: Add explicit condition in print_color_string() Maks Mishin
@ 2024-02-15  3:00 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2024-02-15  3:00 UTC (permalink / raw)
  To: Maks Mishin; +Cc: netdev

On Tue, 13 Feb 2024 23:40:09 +0300
Maks Mishin <maks.mishinfz@gmail.com> 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.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>

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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-15  3:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-13 20:40 [PATCH] json_print: Add explicit condition in print_color_string() Maks Mishin
2024-02-15  3:00 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).