Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cmetrics/.github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:
submodules: true

- name: Build on ${{ matrix.os }} with ${{ matrix.compiler }}
uses: uraimo/run-on-arch-action@v3.0.1
uses: uraimo/run-on-arch-action@v3.1.0
with:
arch: aarch64
distro: ubuntu_latest
Expand Down
4 changes: 2 additions & 2 deletions lib/cmetrics/.github/workflows/packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
submodules: true

- uses: uraimo/run-on-arch-action@v3.0.1
- uses: uraimo/run-on-arch-action@v3.1.0
name: Build the ${{matrix.format}} packages
with:
arch: aarch64
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
artifacts/**/*

- name: Release on tag
uses: softprops/action-gh-release@v2
uses: softprops/action-gh-release@v3
if: startsWith(github.ref, 'refs/tags/')
with:
generate_release_notes: true
Expand Down
2 changes: 1 addition & 1 deletion lib/cmetrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# CMetrics Version
set(CMT_VERSION_MAJOR 2)
set(CMT_VERSION_MINOR 1)
set(CMT_VERSION_PATCH 2)
set(CMT_VERSION_PATCH 3)
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")

# Include helpers
Expand Down
167 changes: 164 additions & 3 deletions lib/cmetrics/src/cmt_decode_msgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <cmetrics/cmt_mpack_utils.h>
#include <cmetrics/cmt_atomic.h>

#include <limits.h>

static int create_counter_instance(struct cmt_map *map)
{
Expand Down Expand Up @@ -330,6 +331,7 @@ static int unpack_label(mpack_reader_t *reader,
size_t index,
struct cfl_list *target_label_list)
{
mpack_tag_t tag;
struct cmt_map_label *new_label;
int result;

Expand All @@ -344,7 +346,27 @@ static int unpack_label(mpack_reader_t *reader,
return CMT_DECODE_MSGPACK_ALLOCATION_ERROR;
}

result = cmt_mpack_consume_string_tag(reader, &new_label->name);
tag = mpack_peek_tag(reader);
if (mpack_ok != mpack_reader_error(reader)) {
free(new_label);

return CMT_DECODE_MSGPACK_CORRUPT_INPUT_DATA_ERROR;
}

if (mpack_tag_type(&tag) == mpack_type_nil) {
mpack_expect_nil(reader);
if (mpack_ok != mpack_reader_error(reader)) {
free(new_label);

return CMT_DECODE_MSGPACK_CORRUPT_INPUT_DATA_ERROR;
}

new_label->name = NULL;
result = CMT_DECODE_MSGPACK_SUCCESS;
}
else {
result = cmt_mpack_consume_string_tag(reader, &new_label->name);
}

if (result != CMT_DECODE_MSGPACK_SUCCESS) {
free(new_label);
Expand Down Expand Up @@ -520,6 +542,11 @@ static int unpack_metric_value_type(mpack_reader_t *reader, size_t index, void *
int result;
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;

result = cmt_mpack_consume_uint_tag(reader, &value);
Expand All @@ -529,6 +556,9 @@ static int unpack_metric_value_type(mpack_reader_t *reader, size_t index, void *
value == CMT_METRIC_VALUE_DOUBLE) {
cmt_atomic_store(&decode_context->metric->value_type, value);
}
else {
result = CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}
}

return result;
Expand All @@ -540,6 +570,11 @@ static int unpack_metric_value_int64(mpack_reader_t *reader, size_t index, void
int result;
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
result = cmt_mpack_consume_int_tag(reader, &value);
if (result == CMT_DECODE_MSGPACK_SUCCESS) {
Expand All @@ -558,6 +593,11 @@ static int unpack_metric_value_uint64(mpack_reader_t *reader, size_t index, void
int result;
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
result = cmt_mpack_consume_uint_tag(reader, &value);
if (result == CMT_DECODE_MSGPACK_SUCCESS) {
Expand Down Expand Up @@ -863,9 +903,18 @@ static int unpack_exp_histogram_scale(mpack_reader_t *reader, size_t index, void
int64_t value;
int result;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
result = cmt_mpack_consume_int_tag(reader, &value);
if (result == CMT_DECODE_MSGPACK_SUCCESS) {
if (value < INT_MIN || value > INT_MAX) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context->metric->exp_hist_scale = (int32_t) value;
}
return result;
Expand All @@ -874,13 +923,25 @@ static int unpack_exp_histogram_scale(mpack_reader_t *reader, size_t index, void
static int unpack_exp_histogram_zero_count(mpack_reader_t *reader, size_t index, void *context)
{
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
return cmt_mpack_consume_uint_tag(reader, &decode_context->metric->exp_hist_zero_count);
}

static int unpack_exp_histogram_zero_threshold(mpack_reader_t *reader, size_t index, void *context)
{
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
return cmt_mpack_consume_double_tag(reader, &decode_context->metric->exp_hist_zero_threshold);
}
Expand All @@ -891,9 +952,18 @@ static int unpack_exp_histogram_positive_offset(mpack_reader_t *reader, size_t i
int64_t value;
int result;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
result = cmt_mpack_consume_int_tag(reader, &value);
if (result == CMT_DECODE_MSGPACK_SUCCESS) {
if (value < INT_MIN || value > INT_MAX) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context->metric->exp_hist_positive_offset = (int32_t) value;
}
return result;
Expand All @@ -905,9 +975,18 @@ static int unpack_exp_histogram_negative_offset(mpack_reader_t *reader, size_t i
int64_t value;
int result;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
result = cmt_mpack_consume_int_tag(reader, &value);
if (result == CMT_DECODE_MSGPACK_SUCCESS) {
if (value < INT_MIN || value > INT_MAX) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context->metric->exp_hist_negative_offset = (int32_t) value;
}
return result;
Expand All @@ -916,14 +995,36 @@ static int unpack_exp_histogram_negative_offset(mpack_reader_t *reader, size_t i
static int unpack_exp_histogram_positive_bucket(mpack_reader_t *reader, size_t index, void *context)
{
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
if (decode_context->metric->exp_hist_positive_buckets == NULL ||
index >= decode_context->metric->exp_hist_positive_count) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

return cmt_mpack_consume_uint_tag(reader, &decode_context->metric->exp_hist_positive_buckets[index]);
}

static int unpack_exp_histogram_negative_bucket(mpack_reader_t *reader, size_t index, void *context)
{
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
if (decode_context->metric->exp_hist_negative_buckets == NULL ||
index >= decode_context->metric->exp_hist_negative_count) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

return cmt_mpack_consume_uint_tag(reader, &decode_context->metric->exp_hist_negative_buckets[index]);
}

Expand All @@ -932,6 +1033,11 @@ static int unpack_exp_histogram_positive_buckets(mpack_reader_t *reader, size_t
struct cmt_msgpack_decode_context *decode_context;
size_t count;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
count = cmt_mpack_peek_array_length(reader);

Expand All @@ -957,6 +1063,11 @@ static int unpack_exp_histogram_negative_buckets(mpack_reader_t *reader, size_t
struct cmt_msgpack_decode_context *decode_context;
size_t count;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
count = cmt_mpack_peek_array_length(reader);

Expand All @@ -983,6 +1094,11 @@ static int unpack_exp_histogram_count(mpack_reader_t *reader, size_t index, void
uint64_t value;
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
result = cmt_mpack_consume_uint_tag(reader, &value);

Expand All @@ -999,6 +1115,11 @@ static int unpack_exp_histogram_sum_set(mpack_reader_t *reader, size_t index, vo
uint64_t value;
int result;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
result = cmt_mpack_consume_uint_tag(reader, &value);

Expand All @@ -1016,6 +1137,11 @@ static int unpack_exp_histogram_sum(mpack_reader_t *reader, size_t index, void *
uint64_t value;
struct cmt_msgpack_decode_context *decode_context;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
result = cmt_mpack_consume_uint_tag(reader, &value);

Expand Down Expand Up @@ -1313,6 +1439,19 @@ static int unpack_meta_type(mpack_reader_t *reader, size_t index, void *context)
result = cmt_mpack_consume_uint_tag(reader, &value);

if (CMT_DECODE_MSGPACK_SUCCESS == result) {
if (decode_context->map->parent != NULL) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

if (value != CMT_COUNTER &&
value != CMT_GAUGE &&
value != CMT_SUMMARY &&
value != CMT_HISTOGRAM &&
value != CMT_EXP_HISTOGRAM &&
value != CMT_UNTYPED) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context->map->type = value;

result = create_metric_instance(decode_context->map);
Expand All @@ -1337,6 +1476,12 @@ static int unpack_meta_aggregation_type(mpack_reader_t *reader, size_t index, vo
result = cmt_mpack_consume_uint_tag(reader, &value);

if (CMT_DECODE_MSGPACK_SUCCESS == result) {
if (value != CMT_AGGREGATION_TYPE_UNSPECIFIED &&
value != CMT_AGGREGATION_TYPE_DELTA &&
value != CMT_AGGREGATION_TYPE_CUMULATIVE) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context->aggregation_type = value;
}

Expand All @@ -1346,13 +1491,23 @@ static int unpack_meta_aggregation_type(mpack_reader_t *reader, size_t index, vo
static int unpack_meta_opts(mpack_reader_t *reader, size_t index, void *context)
{
struct cmt_msgpack_decode_context *decode_context;
struct cmt_opts *opts;

if (NULL == reader ||
NULL == context) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

decode_context = (struct cmt_msgpack_decode_context *) context;
opts = decode_context->map->opts;
if (opts == NULL ||
opts->ns != NULL ||
opts->subsystem != NULL ||
opts->name != NULL ||
opts->description != NULL ||
decode_context->map->unit != NULL) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

return unpack_opts(reader, decode_context->map);
}
Expand Down Expand Up @@ -1505,9 +1660,13 @@ static int unpack_basic_type_meta(mpack_reader_t *reader, size_t index, void *co
result = cmt_mpack_unpack_map(reader, callbacks, context);

if (CMT_DECODE_MSGPACK_SUCCESS == result) {
if (decode_context->map == NULL || decode_context->map->parent == NULL) {
if (decode_context->map == NULL ||
decode_context->map->parent == NULL ||
decode_context->map->opts == NULL ||
decode_context->map->opts->name == NULL ||
decode_context->map->opts->description == NULL) {
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

decode_context->map->label_count = cfl_list_size(&decode_context->map->label_keys);
if (decode_context->map->type == CMT_HISTOGRAM) {
Expand Down Expand Up @@ -1995,6 +2154,8 @@ int cmt_decode_msgpack_create(struct cmt **out_cmt, char *in_buf, size_t in_size
return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR;
}

*out_cmt = NULL;

if (0 == in_size ||
0 == (in_size - *offset) ) {
return CMT_DECODE_MSGPACK_INSUFFICIENT_DATA;
Expand Down
Loading
Loading