From acff4f05a394572cca7307ee57708d538affc1a7 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 26 Aug 2024 12:34:57 -0600 Subject: [PATCH 1/2] encoding: opentelemetry: do not memcpy on null ref (CID 508108) Signed-off-by: Eduardo Silva --- src/cmt_encode_opentelemetry.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmt_encode_opentelemetry.c b/src/cmt_encode_opentelemetry.c index 8c93418..8378bc8 100644 --- a/src/cmt_encode_opentelemetry.c +++ b/src/cmt_encode_opentelemetry.c @@ -711,13 +711,13 @@ static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_binary_to_ result->bytes_value.len = cfl_sds_len(value->data.as_bytes); result->bytes_value.data = calloc(result->bytes_value.len, sizeof(char)); - if (result->bytes_value.data == NULL) { + if (result->bytes_value.data) { + memcpy(result->bytes_value.data, value->data.as_bytes, result->bytes_value.len); + } + else { otlp_any_value_destroy(result); - result = NULL; } - - memcpy(result->bytes_value.data, value->data.as_bytes, result->bytes_value.len); } return result; From 9711d3e81cab5a0e1044619f72618873fc666c11 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 26 Aug 2024 12:25:32 -0600 Subject: [PATCH 2/2] tests: prometheus_parser: add issue flb 9267 Signed-off-by: Eduardo Silva --- tests/data/issue_fluent_bit_9267.txt | 1 + tests/prometheus_parser.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/data/issue_fluent_bit_9267.txt diff --git a/tests/data/issue_fluent_bit_9267.txt b/tests/data/issue_fluent_bit_9267.txt new file mode 100644 index 0000000..979183b --- /dev/null +++ b/tests/data/issue_fluent_bit_9267.txt @@ -0,0 +1 @@ +_bu_nn 0 171798732 \ No newline at end of file diff --git a/tests/prometheus_parser.c b/tests/prometheus_parser.c index 8cdef46..8be8bdd 100644 --- a/tests/prometheus_parser.c +++ b/tests/prometheus_parser.c @@ -261,7 +261,7 @@ void test_escape_sequences() } void test_metric_without_labels() -{ +{ cfl_sds_t result; const char expected[] = @@ -776,7 +776,7 @@ void test_issue_fluent_bit_5541() "http_request_duration_seconds_bucket{le=\"0.25\"} 2 0\n" "http_request_duration_seconds_bucket{le=\"0.5\"} 2 0\n" "http_request_duration_seconds_bucket{le=\"0.75\"} 2 0\n" - "http_request_duration_seconds_bucket{le=\"1.0\"} 2 0\n" + "http_request_duration_seconds_bucket{le=\"1.0\"} 2 0\n" "http_request_duration_seconds_bucket{le=\"2.5\"} 2 0\n" "http_request_duration_seconds_bucket{le=\"5.0\"} 2 0\n" "http_request_duration_seconds_bucket{le=\"7.5\"} 2 0\n" @@ -1665,6 +1665,29 @@ void test_issue_fluent_bit_6534() cmt_decode_prometheus_destroy(cmt); } +void test_issue_fluent_bit_9267() +{ + char errbuf[256]; + int status; + cfl_sds_t result = NULL; + struct cmt *cmt; + struct cmt_decode_prometheus_parse_opts opts; + memset(&opts, 0, sizeof(opts)); + opts.errbuf = errbuf; + opts.errbuf_size = sizeof(errbuf); + cfl_sds_t in_buf = read_file(CMT_TESTS_DATA_PATH "/issue_fluent_bit_9267.txt"); + size_t in_size = cfl_sds_len(in_buf); + + status = cmt_decode_prometheus_create(&cmt, in_buf, in_size, &opts); + TEST_CHECK(status == 0); + if (status) { + fprintf(stderr, "PARSE ERROR:\n======\n%s\n======\n", errbuf); + } + + cmt_decode_prometheus_destroy(cmt); + cfl_sds_destroy(in_buf); +} + TEST_LIST = { {"header_help", test_header_help}, {"header_type", test_header_type}, @@ -1697,5 +1720,6 @@ TEST_LIST = { {"pr_168", test_pr_168}, {"histogram_different_label_count", test_histogram_different_label_count}, {"issue_fluent_bit_6534", test_issue_fluent_bit_6534}, + {"issue_fluent_bit_9267", test_issue_fluent_bit_9267}, { 0 } };