From b46969a9130bc1bc843513ad9ca72e2163d8eeda Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 16 Nov 2016 21:00:54 -0500 Subject: [PATCH] Freeze original field type copied on validation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The following situation should fail: field_type = create a structure FT with a sequence or variant FT field ec = bt_ctf_event_class_create("ec") bt_ctf_event_class_set_payload_type(ec, field_type) sc = bt_ctf_stream_class_create("sc") bt_ctf_stream_class_add_event_class(sc, ec) modify field_type in any way -> should fail In this scenario, field_type gets copied when the validation process is executed in bt_ctf_stream_class_create() because it contains a sequence or variant FT. The original field type, field_type, should also be frozen when this validation succeeds so that it behaves like it was not copied in the first place. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/validation.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/formats/ctf/ir/validation.c b/formats/ctf/ir/validation.c index f3a2c71e1..dc2a3a931 100644 --- a/formats/ctf/ir/validation.c +++ b/formats/ctf/ir/validation.c @@ -563,10 +563,14 @@ void bt_ctf_validation_replace_types(struct bt_ctf_trace *trace, enum bt_ctf_validation_flag replace_flags) { if ((replace_flags & BT_CTF_VALIDATION_FLAG_TRACE) && trace) { + bt_ctf_field_type_freeze(trace->packet_header_type); BT_MOVE(trace->packet_header_type, output->packet_header_type); } if ((replace_flags & BT_CTF_VALIDATION_FLAG_STREAM) && stream_class) { + bt_ctf_field_type_freeze(stream_class->packet_context_type); + bt_ctf_field_type_freeze(stream_class->event_header_type); + bt_ctf_field_type_freeze(stream_class->event_context_type); BT_MOVE(stream_class->packet_context_type, output->packet_context_type); BT_MOVE(stream_class->event_header_type, @@ -576,6 +580,8 @@ void bt_ctf_validation_replace_types(struct bt_ctf_trace *trace, } if ((replace_flags & BT_CTF_VALIDATION_FLAG_EVENT) && event_class) { + bt_ctf_field_type_freeze(event_class->context); + bt_ctf_field_type_freeze(event_class->fields); BT_MOVE(event_class->context, output->event_context_type); BT_MOVE(event_class->fields, output->event_payload_type); } -- 2.34.1