Fix: Check validity of returned ctf_type_id
[babeltrace.git] / formats / ctf / ir / visitor.c
index 5838ddd5007d44cac74dd6a88039dfde64bf709f..9082138d6669151eb549a25fbefc8ac25ee715c6 100644 (file)
@@ -646,6 +646,11 @@ int get_field_path(struct ctf_type_visitor_context *context,
                token = strtok_r(NULL, ".", &save_ptr);
        }
 
+       if (!path_tokens) {
+               ret = -1;
+               goto error;
+       }
+
        *field_path = bt_ctf_field_path_create();
        if (!*field_path) {
                ret = -1;
@@ -717,10 +722,16 @@ void print_path(const char *field_name,
                struct bt_ctf_field_path *field_path)
 {
        int i;
+       enum ctf_type_id type_id = bt_ctf_field_type_get_type_id(
+               resolved_type);
+
+       if (type_id < CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) {
+               type_id = CTF_TYPE_UNKNOWN;
+       }
 
        printf_verbose("Resolved field \"%s\" as type \"%s\", ",
                field_name,
-               type_names[bt_ctf_field_type_get_type_id(resolved_type)]);
+               type_names[type_id]);
        printf_verbose("path: %s",
                absolute_path_prefixes[field_path->root]);
 
This page took 0.023793 seconds and 4 git commands to generate.