Fix ctf-writer: Reject enumerations containing no mappings
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 18 Nov 2013 04:23:03 +0000 (23:23 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Nov 2013 14:57:33 +0000 (09:57 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/writer/event-fields.c
formats/ctf/writer/event-types.c
include/babeltrace/ctf-writer/event-types-internal.h

index ff970c0a86959fee1ce87ddcd2138dcb2b1b4c92..ad4fcb5a06c1ed5d3ad4e5636fdfab603f832623 100644 (file)
@@ -179,8 +179,8 @@ struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type)
        }
 
        type_id = bt_ctf_field_type_get_type_id(type);
-       if (type_id <= CTF_TYPE_UNKNOWN ||
-               type_id >= NR_CTF_TYPES) {
+       if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES ||
+               bt_ctf_field_type_validate(type)) {
                goto error;
        }
 
index fa4e71314a7dc213b6cd15e01ddde04c701e17ad..4ed9fed9942920bff28b6617d6f377d88a0aed93 100644 (file)
@@ -238,6 +238,27 @@ end:
        return ret;
 }
 
+BT_HIDDEN
+int bt_ctf_field_type_validate(struct bt_ctf_field_type *type)
+{
+       int ret = 0;
+
+       if (!type) {
+               ret = -1;
+               goto end;
+       }
+
+       if (type->declaration->id == CTF_TYPE_ENUM) {
+               struct bt_ctf_field_type_enumeration *enumeration =
+                       container_of(type, struct bt_ctf_field_type_enumeration,
+                       parent);
+
+               ret = enumeration->entries->len ? 0 : -1;
+       }
+end:
+       return ret;
+}
+
 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size)
 {
        struct bt_ctf_field_type_integer *integer =
@@ -517,7 +538,8 @@ int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *type,
 
        if (!type || !field_type || type->frozen ||
                validate_identifier(field_name) ||
-               (type->declaration->id != CTF_TYPE_STRUCT)) {
+               (type->declaration->id != CTF_TYPE_STRUCT) ||
+               bt_ctf_field_type_validate(field_type)) {
                goto end;
        }
 
@@ -579,7 +601,8 @@ int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *type,
 
        if (!type || !field_type || type->frozen ||
                validate_identifier(field_name) ||
-               (type->declaration->id != CTF_TYPE_VARIANT)) {
+               (type->declaration->id != CTF_TYPE_VARIANT) ||
+               bt_ctf_field_type_validate(field_type)) {
                ret = -1;
                goto end;
        }
@@ -611,7 +634,8 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_create(
 {
        struct bt_ctf_field_type_array *array = NULL;
 
-       if (!element_type || length == 0) {
+       if (!element_type || length == 0 ||
+               bt_ctf_field_type_validate(element_type)) {
                goto error;
        }
 
@@ -639,7 +663,8 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(
 {
        struct bt_ctf_field_type_sequence *sequence = NULL;
 
-       if (!element_type || validate_identifier(length_field_name)) {
+       if (!element_type || validate_identifier(length_field_name) ||
+               bt_ctf_field_type_validate(element_type)) {
                goto error;
        }
 
@@ -1154,10 +1179,15 @@ int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type *type,
                struct metadata_context *context)
 {
        size_t entry;
-       int ret = 0;
+       int ret;
        struct bt_ctf_field_type_enumeration *enumeration = container_of(type,
                struct bt_ctf_field_type_enumeration, parent);
 
+       ret = bt_ctf_field_type_validate(type);
+       if (ret) {
+               goto end;
+       }
+
        g_string_append(context->string, "enum : ");
        ret = bt_ctf_field_type_serialize(enumeration->container, context);
        if (ret) {
index d9acdd350cad7aa52323cdb62ae035b795ae721b..a937c7803ee889612632f67836a3acaa8edfd092 100644 (file)
@@ -147,4 +147,7 @@ BT_HIDDEN
 int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type,
                struct metadata_context *context);
 
+BT_HIDDEN
+int bt_ctf_field_type_validate(struct bt_ctf_field_type *type);
+
 #endif /* BABELTRACE_CTF_WRITER_EVENT_TYPES_INTERNAL_H */
This page took 0.027149 seconds and 4 git commands to generate.