Skip to content

Commit

Permalink
decode_prometheus: fixed constant pointer release (#219)
Browse files Browse the repository at this point in the history
* tests: prometheus_parser: add issue flb 9267

Signed-off-by: Eduardo Silva <[email protected]>

* decode_prometheus: fixed constant pointer release

Signed-off-by: Leonardo Alminana <[email protected]>

* tests: fixed uninitialized value and erroneous release call

Signed-off-by: Leonardo Alminana <[email protected]>

* encoding: opentelemetry: do not memcpy on null ref (CID 508108)

Signed-off-by: Eduardo Silva <[email protected]>

* tests: prometheus_parser: add issue flb 9267

Signed-off-by: Eduardo Silva <[email protected]>

---------

Signed-off-by: Eduardo Silva <[email protected]>
Signed-off-by: Leonardo Alminana <[email protected]>
Co-authored-by: Eduardo Silva <[email protected]>
  • Loading branch information
leonardo-albertovich and edsiper authored Aug 31, 2024
1 parent 9711d3e commit 9bdc527
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/cmt_decode_prometheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ static void reset_context(struct cmt_decode_prometheus_context *context,
}

if (context->metric.ns) {
if (strcmp(context->metric.ns, "")) {
if ((void *) context->metric.ns != (void *) "") {
/* when namespace is empty, "name" contains a pointer to the
* allocated string */
* allocated string.
*
* Note : When the metric name doesn't include the namespace
* ns is set to a constant empty string and we need to
* differentiate that case from the case where an empty
* namespace is provided.
*/

free(context->metric.ns);
}
else {
Expand Down Expand Up @@ -516,7 +523,7 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
"failed to parse bucket");
goto end;
}
if (parse_uint64(sample->value1,
if (parse_uint64(sample->value1,
bucket_defaults + bucket_index)) {
/* Count is supposed to be integer, but apparently
* some tools can generate count in a floating format.
Expand Down
5 changes: 4 additions & 1 deletion tests/prometheus_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1678,13 +1678,16 @@ void test_issue_fluent_bit_9267()
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);

cmt = NULL;
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);
if (cmt != NULL) {
cmt_decode_prometheus_destroy(cmt);
}
cfl_sds_destroy(in_buf);
}

Expand Down

0 comments on commit 9bdc527

Please sign in to comment.