struct debug_info *debug_info,
struct debug_info_component *component)
{
- struct bt_ctf_field_type *writer_event_context_type = NULL;
+ struct bt_ctf_field_type *writer_event_context_type = NULL,
+ *event_context_type = NULL;
struct bt_ctf_field *writer_event_context = NULL;
struct bt_ctf_field *field = NULL, *copy_field = NULL, *debug_field = NULL;
struct bt_ctf_field_type *field_type = NULL;
goto error;
}
+ event_context_type = bt_ctf_field_get_type(event_context);
+ if (!event_context_type) {
+ fprintf(err, "[error] %s in %s:%d\n", __func__,
+ __FILE__, __LINE__);
+ goto error;
+ }
+
/*
* If it is not a structure, we did not modify it to add the debug info
* fields, so just assign it as is.
goto error;
}
- field = bt_ctf_field_structure_get_field_by_index(event_context, i);
+ /*
+ * Prevent illegal access in the event_context.
+ */
+ if (i < bt_ctf_field_type_structure_get_field_count(event_context_type)) {
+ field = bt_ctf_field_structure_get_field_by_index(event_context, i);
+ }
/*
* The debug_info field, only exists in the writer event or
* if it was set by a earlier pass of the debug_info plugin.
- *
- * FIXME: are we replacing an exisiting debug_info struct here ??
*/
if (!strcmp(field_name, component->arg_debug_info_field_name) &&
!field) {
error:
ret = -1;
end:
+ bt_put(event_context_type);
bt_put(writer_event_context_type);
bt_put(writer_event_context);
bt_put(field);