Fix: Dereference null return value
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 24 Jul 2017 21:26:57 +0000 (17:26 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 9 Aug 2017 22:00:19 +0000 (18:00 -0400)
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 <jeremie.galarneau@efficios.com>
plugins/text/pretty/print.c

index 7cf9434d969fb550b36f66536453f7c511d06835..97e9bf11ce1aa3bb9a73cba8a60ea35da8220720 100644 (file)
@@ -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);
This page took 0.024822 seconds and 4 git commands to generate.