diff --git a/lib/cfl/CMakeLists.txt b/lib/cfl/CMakeLists.txt index 98ee88f7cd6..3f8424dffc7 100644 --- a/lib/cfl/CMakeLists.txt +++ b/lib/cfl/CMakeLists.txt @@ -5,8 +5,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # C Floppy Version set(CFL_VERSION_MAJOR 0) -set(CFL_VERSION_MINOR 2) -set(CFL_VERSION_PATCH 2) +set(CFL_VERSION_MINOR 3) +set(CFL_VERSION_PATCH 0) set(CFL_VERSION_STR "${CFL_VERSION_MAJOR}.${CFL_VERSION_MINOR}.${CFL_VERSION_PATCH}") # Configuration options diff --git a/lib/cfl/include/cfl/cfl_array.h b/lib/cfl/include/cfl/cfl_array.h index e260d24d3fc..bc525013174 100644 --- a/lib/cfl/include/cfl/cfl_array.h +++ b/lib/cfl/include/cfl/cfl_array.h @@ -52,6 +52,7 @@ int cfl_array_append_bytes(struct cfl_array *array, char *value, size_t length); int cfl_array_append_reference(struct cfl_array *array, void *value); int cfl_array_append_bool(struct cfl_array *array, int value); int cfl_array_append_int64(struct cfl_array *array, int64_t value); +int cfl_array_append_uint64(struct cfl_array *array, uint64_t value); int cfl_array_append_double(struct cfl_array *array, double value); int cfl_array_append_array(struct cfl_array *array, struct cfl_array *value); int cfl_array_append_new_array(struct cfl_array *array, size_t size); diff --git a/lib/cfl/include/cfl/cfl_kvlist.h b/lib/cfl/include/cfl/cfl_kvlist.h index 5f920e583e0..d766e9656c4 100644 --- a/lib/cfl/include/cfl/cfl_kvlist.h +++ b/lib/cfl/include/cfl/cfl_kvlist.h @@ -54,6 +54,9 @@ int cfl_kvlist_insert_bool(struct cfl_kvlist *list, int cfl_kvlist_insert_int64(struct cfl_kvlist *list, char *key, int64_t value); +int cfl_kvlist_insert_uint64(struct cfl_kvlist *list, + char *key, uint64_t value); + int cfl_kvlist_insert_double(struct cfl_kvlist *list, char *key, double value); diff --git a/lib/cfl/include/cfl/cfl_variant.h b/lib/cfl/include/cfl/cfl_variant.h index 6249ffdd1e4..964dc2ebf18 100644 --- a/lib/cfl/include/cfl/cfl_variant.h +++ b/lib/cfl/include/cfl/cfl_variant.h @@ -31,6 +31,7 @@ #define CFL_VARIANT_KVLIST 6 #define CFL_VARIANT_BYTES 7 #define CFL_VARIANT_REFERENCE 8 +#define CFL_VARIANT_UINT 9 struct cfl_array; struct cfl_kvlist; @@ -43,6 +44,7 @@ struct cfl_variant { cfl_sds_t as_bytes; unsigned int as_bool; int64_t as_int64; + uint64_t as_uint64; double as_double; void *as_reference; struct cfl_array *as_array; @@ -54,6 +56,7 @@ struct cfl_variant *cfl_variant_create_from_string(char *value); struct cfl_variant *cfl_variant_create_from_bytes(char *value, size_t length); struct cfl_variant *cfl_variant_create_from_bool(int value); struct cfl_variant *cfl_variant_create_from_int64(int64_t value); +struct cfl_variant *cfl_variant_create_from_uint64(uint64_t value); struct cfl_variant *cfl_variant_create_from_double(double value); struct cfl_variant *cfl_variant_create_from_array(struct cfl_array *value); struct cfl_variant *cfl_variant_create_from_kvlist(struct cfl_kvlist *value); diff --git a/lib/cfl/src/cfl_array.c b/lib/cfl/src/cfl_array.c index e64fbf5235f..e9b87c77fc5 100644 --- a/lib/cfl/src/cfl_array.c +++ b/lib/cfl/src/cfl_array.c @@ -261,6 +261,27 @@ int cfl_array_append_int64(struct cfl_array *array, int64_t value) return 0; } +int cfl_array_append_uint64(struct cfl_array *array, uint64_t value) +{ + struct cfl_variant *value_instance; + int result; + + value_instance = cfl_variant_create_from_uint64(value); + + if (value_instance == NULL) { + return -1; + } + + result = cfl_array_append(array, value_instance); + + if (result) { + cfl_variant_destroy(value_instance); + return -2; + } + + return 0; +} + int cfl_array_append_double(struct cfl_array *array, double value) { diff --git a/lib/cfl/src/cfl_kvlist.c b/lib/cfl/src/cfl_kvlist.c index 56139b87cdd..bdfc9f0375d 100644 --- a/lib/cfl/src/cfl_kvlist.c +++ b/lib/cfl/src/cfl_kvlist.c @@ -212,6 +212,29 @@ int cfl_kvlist_insert_int64(struct cfl_kvlist *list, return 0; } +int cfl_kvlist_insert_uint64(struct cfl_kvlist *list, + char *key, uint64_t value) +{ + struct cfl_variant *value_instance; + int result; + + value_instance = cfl_variant_create_from_uint64(value); + + if (value_instance == NULL) { + return -1; + } + + result = cfl_kvlist_insert(list, key, value_instance); + + if (result) { + cfl_variant_destroy(value_instance); + + return -2; + } + + return 0; +} + int cfl_kvlist_insert_double(struct cfl_kvlist *list, char *key, double value) { diff --git a/lib/cfl/src/cfl_variant.c b/lib/cfl/src/cfl_variant.c index 6181066ef57..455af099bdc 100644 --- a/lib/cfl/src/cfl_variant.c +++ b/lib/cfl/src/cfl_variant.c @@ -53,6 +53,9 @@ int cfl_variant_print(FILE *fp, struct cfl_variant *val) case CFL_VARIANT_INT: ret = fprintf(fp, "%" PRId64, val->data.as_int64); break; + case CFL_VARIANT_UINT: + ret = fprintf(fp, "%" PRIu64, val->data.as_uint64); + break; case CFL_VARIANT_DOUBLE: ret = fprintf(fp, "%lf", val->data.as_double); break; @@ -146,6 +149,19 @@ struct cfl_variant *cfl_variant_create_from_int64(int64_t value) return instance; } +struct cfl_variant *cfl_variant_create_from_uint64(uint64_t value) +{ + struct cfl_variant *instance; + + instance = cfl_variant_create(); + if (instance != NULL) { + instance->data.as_uint64 = value; + instance->type = CFL_VARIANT_UINT; + } + + return instance; +} + struct cfl_variant *cfl_variant_create_from_double(double value) { struct cfl_variant *instance; diff --git a/lib/cfl/tests/variant.c b/lib/cfl/tests/variant.c index 83dcb33aa73..2bb2853085f 100644 --- a/lib/cfl/tests/variant.c +++ b/lib/cfl/tests/variant.c @@ -144,6 +144,45 @@ static void test_variant_print_int64() } } +static void test_variant_print_uint64() +{ + int ret; + int i; + uint64_t inputs[] = {1, 0, 18446744073709551615ULL}; + char *expects[] = {"1", "0", "18446744073709551615" /*UINT64_MAX*/}; + + FILE *fp = NULL; + struct cfl_variant *val = NULL; + + for (i=0; i 0)) { + TEST_MSG("%d:cfl_variant_print failed", i); + cfl_variant_destroy(val); + fclose(fp); + continue; + } + ret = compare(fp, expects[i], 0); + if (!TEST_CHECK(ret == 0)) { + TEST_MSG("%d:compare failed", i); + } + cfl_variant_destroy(val); + fclose(fp); + } +} + static void test_variant_print_array() { int ret; @@ -459,6 +498,7 @@ static void test_variant_print_unknown() TEST_LIST = { {"variant_print_bool", test_variant_print_bool}, {"variant_print_int64", test_variant_print_int64}, + {"variant_print_uint64", test_variant_print_uint64}, {"variant_print_double", test_variant_print_double}, {"variant_print_string", test_variant_print_string}, {"variant_print_bytes", test_variant_print_bytes}, diff --git a/lib/cmetrics/CMakeLists.txt b/lib/cmetrics/CMakeLists.txt index 4cb426c4447..01826099978 100644 --- a/lib/cmetrics/CMakeLists.txt +++ b/lib/cmetrics/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # CMetrics Version set(CMT_VERSION_MAJOR 0) set(CMT_VERSION_MINOR 6) -set(CMT_VERSION_PATCH 5) +set(CMT_VERSION_PATCH 6) set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}") # Include helpers diff --git a/lib/ctraces/CMakeLists.txt b/lib/ctraces/CMakeLists.txt index 08e1b6d29b7..12ff6d7c867 100644 --- a/lib/ctraces/CMakeLists.txt +++ b/lib/ctraces/CMakeLists.txt @@ -26,8 +26,8 @@ endif() # CTraces Version set(CTR_VERSION_MAJOR 0) -set(CTR_VERSION_MINOR 3) -set(CTR_VERSION_PATCH 1) +set(CTR_VERSION_MINOR 4) +set(CTR_VERSION_PATCH 0) set(CTR_VERSION_STR "${CTR_VERSION_MAJOR}.${CTR_VERSION_MINOR}.${CTR_VERSION_PATCH}") # Define __FILENAME__ consistently across Operating Systems diff --git a/lib/ctraces/examples/otlp-encoder/otlp-encoder.c b/lib/ctraces/examples/otlp-encoder/otlp-encoder.c index 00b984a40b9..2e178b3e938 100644 --- a/lib/ctraces/examples/otlp-encoder/otlp-encoder.c +++ b/lib/ctraces/examples/otlp-encoder/otlp-encoder.c @@ -107,7 +107,7 @@ int main() ctr_span_event_set_attribute_string(event, "syscall 3", "write()"); /* add a key/value pair list */ - kv = cfl_kvlist_create(1); + kv = cfl_kvlist_create(); cfl_kvlist_insert_string(kv, "language", "c"); ctr_span_set_attribute_kvlist(span_root, "my-list", kv); diff --git a/lib/ctraces/examples/simple-c-api.c b/lib/ctraces/examples/simple-c-api.c index aeaeff120a7..c9a9dfb9dec 100644 --- a/lib/ctraces/examples/simple-c-api.c +++ b/lib/ctraces/examples/simple-c-api.c @@ -102,7 +102,7 @@ int main() ctr_span_event_set_attribute_string(event, "syscall 3", "write()"); /* add a key/value pair list */ - kv = cfl_kvlist_create(1); + kv = cfl_kvlist_create(); cfl_kvlist_insert_string(kv, "language", "c"); ctr_span_set_attribute_kvlist(span_root, "my-list", kv); diff --git a/lib/ctraces/include/ctraces/ctr_variant_utils.h b/lib/ctraces/include/ctraces/ctr_variant_utils.h index c338be1b051..d8f25169ce6 100644 --- a/lib/ctraces/include/ctraces/ctr_variant_utils.h +++ b/lib/ctraces/include/ctraces/ctr_variant_utils.h @@ -22,6 +22,10 @@ #include +#define CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE 100 +#define CFL_VARIANT_UTILS_INITIAL_ARRAY_SIZE 100 +#define CFL_VARIANT_UTILS_SERIALIZED_ARRAY_SIZE_LIMIT 100000 + /* These are the only functions meant for general use, * the reason why the kvlist packing and unpacking * functions are exposed is the internal and external @@ -226,12 +230,25 @@ static inline int unpack_cfl_array(mpack_reader_t *reader, entry_count = mpack_tag_array_count(&tag); - internal_array = cfl_array_create(entry_count); + if (entry_count >= CFL_VARIANT_UTILS_SERIALIZED_ARRAY_SIZE_LIMIT) { + return -2; + } + + if (entry_count >= CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE) { + internal_array = cfl_array_create(CFL_VARIANT_UTILS_INITIAL_ARRAY_SIZE); + } + else { + internal_array = cfl_array_create(entry_count); + } if (internal_array == NULL) { return -3; } + if (entry_count >= CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE) { + cfl_array_resizable(internal_array, CFL_TRUE); + } + for (index = 0 ; index < entry_count ; index++) { result = unpack_cfl_variant(reader, &entry_value); diff --git a/lib/ctraces/src/ctr_attributes.c b/lib/ctraces/src/ctr_attributes.c index 44bb13853e2..67caebb88b7 100644 --- a/lib/ctraces/src/ctr_attributes.c +++ b/lib/ctraces/src/ctr_attributes.c @@ -29,7 +29,7 @@ struct ctrace_attributes *ctr_attributes_create() return NULL; } - attr->kv = cfl_kvlist_create(128); + attr->kv = cfl_kvlist_create(); if (!attr->kv) { free(attr); return NULL; diff --git a/lib/ctraces/src/ctr_decode_msgpack.c b/lib/ctraces/src/ctr_decode_msgpack.c index f1df5c32544..0711aaff492 100644 --- a/lib/ctraces/src/ctr_decode_msgpack.c +++ b/lib/ctraces/src/ctr_decode_msgpack.c @@ -124,6 +124,11 @@ static int unpack_instrumentation_scope_attributes(mpack_reader_t *reader, size_ return CTR_DECODE_MSGPACK_VARIANT_DECODE_ERROR; } + if (context->scope_span->instrumentation_scope->attr != NULL) { + ctr_attributes_destroy(context->scope_span->instrumentation_scope->attr); + context->scope_span->instrumentation_scope->attr = NULL; + } + context->scope_span->instrumentation_scope->attr = attributes; } @@ -132,6 +137,7 @@ static int unpack_instrumentation_scope_attributes(mpack_reader_t *reader, size_ static int unpack_scope_span_instrumentation_scope(mpack_reader_t *reader, size_t index, void *ctx) { + int result; struct ctrace_instrumentation_scope *instrumentation_scope; struct ctr_msgpack_decode_context *context = ctx; struct ctr_mpack_map_entry_callback_t callbacks[] = \ @@ -151,7 +157,12 @@ static int unpack_scope_span_instrumentation_scope(mpack_reader_t *reader, size_ ctr_scope_span_set_instrumentation_scope(context->scope_span, instrumentation_scope); - return ctr_mpack_unpack_map(reader, callbacks, ctx); + result = ctr_mpack_unpack_map(reader, callbacks, ctx); + if (result != CTR_DECODE_MSGPACK_SUCCESS) { + ctr_instrumentation_scope_destroy(context->scope_span->instrumentation_scope); + context->scope_span->instrumentation_scope = NULL; + } + return result; } /* Event callbacks */ @@ -541,6 +552,7 @@ static int unpack_span_status(mpack_reader_t *reader, size_t index, void *ctx) static int unpack_span(mpack_reader_t *reader, size_t index, void *ctx) { + int result; struct ctr_msgpack_decode_context *context = ctx; struct ctr_mpack_map_entry_callback_t callbacks[] = \ { @@ -565,8 +577,14 @@ static int unpack_span(mpack_reader_t *reader, size_t index, void *ctx) if (context->span == NULL) { return CTR_DECODE_MSGPACK_ALLOCATION_ERROR; } + result = ctr_mpack_unpack_map(reader, callbacks, ctx); - return ctr_mpack_unpack_map(reader, callbacks, ctx); + if (result != CTR_DECODE_MSGPACK_SUCCESS) { + ctr_span_destroy(context->span); + context->span = NULL; + } + + return result; } /* Scope span callbacks */ @@ -591,6 +609,7 @@ static int unpack_scope_span_schema_url(mpack_reader_t *reader, size_t index, vo static int unpack_scope_span(mpack_reader_t *reader, size_t index, void *ctx) { + int result; struct ctr_msgpack_decode_context *context = ctx; struct ctr_mpack_map_entry_callback_t callbacks[] = \ { @@ -606,7 +625,12 @@ static int unpack_scope_span(mpack_reader_t *reader, size_t index, void *ctx) return CTR_DECODE_MSGPACK_ALLOCATION_ERROR; } - return ctr_mpack_unpack_map(reader, callbacks, ctx); + result = ctr_mpack_unpack_map(reader, callbacks, ctx); + if (result != CTR_DECODE_MSGPACK_SUCCESS) { + ctr_scope_span_destroy(context->scope_span); + context->scope_span = NULL; + } + return result; } /* Resource span callbacks */ diff --git a/lib/ctraces/src/ctr_decode_opentelemetry.c b/lib/ctraces/src/ctr_decode_opentelemetry.c index 139ae2cd904..ba9f2eb03b1 100644 --- a/lib/ctraces/src/ctr_decode_opentelemetry.c +++ b/lib/ctraces/src/ctr_decode_opentelemetry.c @@ -571,7 +571,9 @@ int ctr_decode_opentelemetry_create(struct ctrace **out_ctr, ctr_span_kind_set(span, otel_span->kind); ctr_span_start_ts(ctr, span, otel_span->start_time_unix_nano); ctr_span_end_ts(ctr, span, otel_span->end_time_unix_nano); - ctr_span_set_status(span, otel_span->status->code, otel_span->status->message); + if (otel_span->status) { + ctr_span_set_status(span, otel_span->status->code, otel_span->status->message); + } ctr_span_set_attributes(span, otel_span->n_attributes, otel_span->attributes); ctr_span_set_events(span, otel_span->n_events, otel_span->events); ctr_span_set_dropped_attributes_count(span, otel_span->dropped_attributes_count); diff --git a/lib/ctraces/src/ctr_span.c b/lib/ctraces/src/ctr_span.c index d93935a7233..6e61f53ea03 100644 --- a/lib/ctraces/src/ctr_span.c +++ b/lib/ctraces/src/ctr_span.c @@ -34,7 +34,7 @@ struct ctrace_span *ctr_span_create(struct ctrace *ctx, struct ctrace_scope_span /* allocate a spanc context */ span = calloc(1, sizeof(struct ctrace_span)); - if (!span) { + if (span == NULL) { ctr_errno(); return NULL; } @@ -45,14 +45,14 @@ struct ctrace_span *ctr_span_create(struct ctrace *ctx, struct ctrace_scope_span /* name */ span->name = cfl_sds_create(name); - if (!span->name) { + if (span->name == NULL) { free(span); return NULL; } /* attributes */ span->attr = ctr_attributes_create(); - if (!span->attr) { + if (span->attr == NULL) { free(span); return NULL; } @@ -116,7 +116,9 @@ int ctr_span_set_span_id(struct ctrace_span *span, void *buf, size_t len) if (!buf || len <= 0) { return -1; } - + if (span->span_id != NULL) { + ctr_id_destroy(span->span_id); + } span->span_id = ctr_id_create(buf, len); if (!span->span_id) { return -1; @@ -294,26 +296,29 @@ void ctr_span_destroy(struct ctrace_span *span) struct ctrace_span_status *status; struct ctrace_link *link; - if (span->name) { + if (span->name != NULL) { cfl_sds_destroy(span->name); } - if (span->trace_id) { + if (span->trace_id != NULL) { ctr_id_destroy(span->trace_id); } - if (span->span_id) { + if (span->span_id != NULL) { ctr_id_destroy(span->span_id); } - if (span->parent_span_id) { + if (span->parent_span_id != NULL) { ctr_id_destroy(span->parent_span_id); } /* attributes */ - if (span->attr) { + if (span->attr != NULL) { ctr_attributes_destroy(span->attr); } + if (span->trace_state != NULL) { + cfl_sds_destroy(span->trace_state); + } /* events */ cfl_list_foreach_safe(head, tmp, &span->events) { @@ -329,7 +334,7 @@ void ctr_span_destroy(struct ctrace_span *span) /* status */ status = &span->status; - if (status->message) { + if (status->message != NULL) { cfl_sds_destroy(status->message); } @@ -346,21 +351,21 @@ struct ctrace_span_event *ctr_span_event_add_ts(struct ctrace_span *span, char * { struct ctrace_span_event *ev; - if (!name) { + if (name == NULL) { return NULL; } ev = calloc(1, sizeof(struct ctrace_span_event)); - if (!ev) { + if (ev == NULL) { ctr_errno(); return NULL; } ev->name = cfl_sds_create(name); - if (!ev->name) { + if (ev->name == NULL) { free(ev); return NULL; } - ev->attr = ctr_attributes_create(128); + ev->attr = ctr_attributes_create(); ev->dropped_attr_count = 0; /* if no timestamp is given, use the current time */ diff --git a/lib/ctraces/tests/decoding.c b/lib/ctraces/tests/decoding.c index ab919b94a42..81076d090f6 100644 --- a/lib/ctraces/tests/decoding.c +++ b/lib/ctraces/tests/decoding.c @@ -581,7 +581,7 @@ void test_simple_to_msgpack_and_back() ctr_span_event_set_attribute_string(event, "syscall 3", "write()"); /* add a key/value pair list */ - kv = cfl_kvlist_create(1); + kv = cfl_kvlist_create(); TEST_ASSERT(kv != NULL); cfl_kvlist_insert_string(kv, "language", "c");