From: Philippe Proulx Date: Thu, 24 Nov 2016 21:44:01 +0000 (-0500) Subject: field-types.c: check that we don't add self FT to struct/var FT X-Git-Tag: v2.0.0-pre1~645 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=73892edccc428bf4d579a176037b14195b852e63 field-types.c: check that we don't add self FT to struct/var FT Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/field-types.c b/formats/ctf/ir/field-types.c index 49919ca2..7f324c9a 100644 --- a/formats/ctf/ir/field-types.c +++ b/formats/ctf/ir/field-types.c @@ -1410,9 +1410,14 @@ int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *type, int ret = 0; struct bt_ctf_field_type_structure *structure; + /* + * TODO: check that `field_type` does not contain `type`, + * recursively. + */ if (!type || !field_type || type->frozen || bt_ctf_validate_identifier(field_name) || - (type->declaration->id != BT_CTF_TYPE_ID_STRUCT)) { + (type->declaration->id != BT_CTF_TYPE_ID_STRUCT) || + type == field_type) { ret = -1; goto end; } @@ -1615,9 +1620,14 @@ int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *type, struct bt_ctf_field_type_variant *variant; GQuark field_name_quark = g_quark_from_string(field_name); + /* + * TODO: check that `field_type` does not contain `type`, + * recursively. + */ if (!type || !field_type || type->frozen || bt_ctf_validate_identifier(field_name) || - (type->declaration->id != BT_CTF_TYPE_ID_VARIANT)) { + (type->declaration->id != BT_CTF_TYPE_ID_VARIANT) || + type == field_type) { ret = -1; goto end; } diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 04e9d996..b6b029c5 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -59,7 +59,7 @@ #define DEFAULT_CLOCK_TIME 0 #define DEFAULT_CLOCK_VALUE 0 -#define NR_TESTS 604 +#define NR_TESTS 605 static int64_t current_time = 42; @@ -786,6 +786,8 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ok(bt_ctf_field_type_array_get_length(array_type) == ARRAY_TEST_LENGTH, "bt_ctf_field_type_array_get_length returns the correct length"); + ok(bt_ctf_field_type_structure_add_field(inner_structure_type, + inner_structure_type, "yes"), "Cannot add self to structure"); ok(!bt_ctf_field_type_structure_add_field(inner_structure_type, uint_35_type, "seq_len"), "Add seq_len field to inner structure"); ok(!bt_ctf_field_type_structure_add_field(inner_structure_type,