Skip to content

Commit 9bdc527

Browse files
leonardo-albertovichedsiper
andauthored
decode_prometheus: fixed constant pointer release (#219)
* 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]>
1 parent 9711d3e commit 9bdc527

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/cmt_decode_prometheus.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ static void reset_context(struct cmt_decode_prometheus_context *context,
5757
}
5858

5959
if (context->metric.ns) {
60-
if (strcmp(context->metric.ns, "")) {
60+
if ((void *) context->metric.ns != (void *) "") {
6161
/* when namespace is empty, "name" contains a pointer to the
62-
* allocated string */
62+
* allocated string.
63+
*
64+
* Note : When the metric name doesn't include the namespace
65+
* ns is set to a constant empty string and we need to
66+
* differentiate that case from the case where an empty
67+
* namespace is provided.
68+
*/
69+
6370
free(context->metric.ns);
6471
}
6572
else {
@@ -516,7 +523,7 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
516523
"failed to parse bucket");
517524
goto end;
518525
}
519-
if (parse_uint64(sample->value1,
526+
if (parse_uint64(sample->value1,
520527
bucket_defaults + bucket_index)) {
521528
/* Count is supposed to be integer, but apparently
522529
* some tools can generate count in a floating format.

tests/prometheus_parser.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,13 +1678,16 @@ void test_issue_fluent_bit_9267()
16781678
cfl_sds_t in_buf = read_file(CMT_TESTS_DATA_PATH "/issue_fluent_bit_9267.txt");
16791679
size_t in_size = cfl_sds_len(in_buf);
16801680

1681+
cmt = NULL;
16811682
status = cmt_decode_prometheus_create(&cmt, in_buf, in_size, &opts);
16821683
TEST_CHECK(status == 0);
16831684
if (status) {
16841685
fprintf(stderr, "PARSE ERROR:\n======\n%s\n======\n", errbuf);
16851686
}
16861687

1687-
cmt_decode_prometheus_destroy(cmt);
1688+
if (cmt != NULL) {
1689+
cmt_decode_prometheus_destroy(cmt);
1690+
}
16881691
cfl_sds_destroy(in_buf);
16891692
}
16901693

0 commit comments

Comments
 (0)