* [lttng-dev] [PATCH babeltrace] Fix ctf-writer: Reject enumerations containing no mappings
@ 2013-11-18 4:23 Jérémie Galarneau
2013-11-19 14:57 ` Mathieu Desnoyers
0 siblings, 1 reply; 2+ messages in thread
From: Jérémie Galarneau @ 2013-11-18 4:23 UTC (permalink / raw)
Signed-off-by: J?r?mie Galarneau <jeremie.galarneau at efficios.com>
---
formats/ctf/writer/event-fields.c | 4 +--
formats/ctf/writer/event-types.c | 40 +++++++++++++++++++---
.../babeltrace/ctf-writer/event-types-internal.h | 3 ++
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/formats/ctf/writer/event-fields.c b/formats/ctf/writer/event-fields.c
index ff970c0..ad4fcb5 100644
--- a/formats/ctf/writer/event-fields.c
+++ b/formats/ctf/writer/event-fields.c
@@ -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;
}
diff --git a/formats/ctf/writer/event-types.c b/formats/ctf/writer/event-types.c
index fa4e713..4ed9fed 100644
--- a/formats/ctf/writer/event-types.c
+++ b/formats/ctf/writer/event-types.c
@@ -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) {
diff --git a/include/babeltrace/ctf-writer/event-types-internal.h b/include/babeltrace/ctf-writer/event-types-internal.h
index d9acdd3..a937c78 100644
--- a/include/babeltrace/ctf-writer/event-types-internal.h
+++ b/include/babeltrace/ctf-writer/event-types-internal.h
@@ -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 */
--
1.8.4.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [lttng-dev] [PATCH babeltrace] Fix ctf-writer: Reject enumerations containing no mappings
2013-11-18 4:23 [lttng-dev] [PATCH babeltrace] Fix ctf-writer: Reject enumerations containing no mappings Jérémie Galarneau
@ 2013-11-19 14:57 ` Mathieu Desnoyers
0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Desnoyers @ 2013-11-19 14:57 UTC (permalink / raw)
Merged, thanks!
Mathieu
----- Original Message -----
> From: "J?r?mie Galarneau" <jeremie.galarneau@efficios.com>
> To: lttng-dev at lists.lttng.org
> Sent: Sunday, November 17, 2013 11:23:03 PM
> Subject: [lttng-dev] [PATCH babeltrace] Fix ctf-writer: Reject enumerations containing no mappings
>
> Signed-off-by: J?r?mie Galarneau <jeremie.galarneau at efficios.com>
> ---
> formats/ctf/writer/event-fields.c | 4 +--
> formats/ctf/writer/event-types.c | 40
> +++++++++++++++++++---
> .../babeltrace/ctf-writer/event-types-internal.h | 3 ++
> 3 files changed, 40 insertions(+), 7 deletions(-)
>
> diff --git a/formats/ctf/writer/event-fields.c
> b/formats/ctf/writer/event-fields.c
> index ff970c0..ad4fcb5 100644
> --- a/formats/ctf/writer/event-fields.c
> +++ b/formats/ctf/writer/event-fields.c
> @@ -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;
> }
>
> diff --git a/formats/ctf/writer/event-types.c
> b/formats/ctf/writer/event-types.c
> index fa4e713..4ed9fed 100644
> --- a/formats/ctf/writer/event-types.c
> +++ b/formats/ctf/writer/event-types.c
> @@ -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) {
> diff --git a/include/babeltrace/ctf-writer/event-types-internal.h
> b/include/babeltrace/ctf-writer/event-types-internal.h
> index d9acdd3..a937c78 100644
> --- a/include/babeltrace/ctf-writer/event-types-internal.h
> +++ b/include/babeltrace/ctf-writer/event-types-internal.h
> @@ -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 */
> --
> 1.8.4.2
>
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-11-19 14:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-18 4:23 [lttng-dev] [PATCH babeltrace] Fix ctf-writer: Reject enumerations containing no mappings Jérémie Galarneau
2013-11-19 14:57 ` Mathieu Desnoyers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox