From d1f0e0e31377de33b95baf5070ac95ea0cb88bba Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 24 Jul 2017 17:26:57 -0400 Subject: [PATCH] Fix: Dereference null return value MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Found by Coverity: 3. returned_null: bt_ctf_field_string_get_value returns null (checked 10 out of 12 times). CID 1376192 (#1 of 1): Dereference null return value (NULL_RETURNS) 4. dereference: Dereferencing a pointer that might be null bt_ctf_field_string_get_value(field) when calling print_escape_string. Signed-off-by: Jérémie Galarneau --- plugins/text/pretty/print.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index 7cf9434d..97e9bf11 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -1317,14 +1317,23 @@ enum bt_component_status print_field(struct pretty_component *pretty, case CTF_TYPE_ENUM: return print_enum(pretty, field); case CTF_TYPE_STRING: + { + const char *str; + + str = bt_ctf_field_string_get_value(field); + if (!str) { + return BT_COMPONENT_STATUS_ERROR; + } + if (pretty->use_colors) { g_string_append(pretty->string, COLOR_STRING_VALUE); } - print_escape_string(pretty, bt_ctf_field_string_get_value(field)); + print_escape_string(pretty, str); if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); } return BT_COMPONENT_STATUS_OK; + } case CTF_TYPE_STRUCT: return print_struct(pretty, field, print_names, filter_fields, filter_array_len); -- 2.34.1