Skip to content

Commit

Permalink
multiline: cri don't create msgpack buffer until validating time
Browse files Browse the repository at this point in the history
Signed-off-by: ryanohnemus <ryanohnemus@gmail.com>
  • Loading branch information
ryanohnemus committed Jan 10, 2025
1 parent 9f0a5f6 commit 9030e20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/flb_parser_cri.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <fluent-bit/flb_unescape.h>
#include <fluent-bit/flb_mem.h>

#define CRI_SPACE_DELIM " "
#define CRI_SPACE_DELIM ' '

int flb_parser_cri_do(struct flb_parser *parser,
const char *in_buf, size_t in_size,
Expand Down Expand Up @@ -56,7 +56,7 @@ int flb_parser_cri_do(struct flb_parser *parser,
time_key_len = strlen(time_key);

/* Time */
token_end = strpbrk(in_buf, CRI_SPACE_DELIM);
token_end = strchr(in_buf, CRI_SPACE_DELIM);

Check failure

Code scanning / ClusterFuzzLite/CIFuzz

A read or write past the end of a heap buffer. Error

Heap-buffer-overflow
READ 2

/* after we find 'time' field (which is variable length),
* we also check that we have enough room for static size fields
Expand All @@ -68,20 +68,20 @@ int flb_parser_cri_do(struct flb_parser *parser,
return -1;
}

/* Prepare new outgoing buffer, then add time to it */
msgpack_sbuffer_init(&tmp_sbuf);
msgpack_packer_init(&tmp_pck, &tmp_sbuf, msgpack_sbuffer_write);
msgpack_pack_map(&tmp_pck, map_size);

struct flb_tm tm = {0};
ret = flb_parser_time_lookup(in_buf, token_end-in_buf-1,
ret = flb_parser_time_lookup(in_buf, token_end-in_buf,
0, parser, &tm, &tmfrac);
if (ret == -1) {
flb_error("[parser:%s] Invalid time format %s",
parser->name, parser->time_fmt_full);
return -1;
}

/* Prepare new outgoing buffer, then add time to it */
msgpack_sbuffer_init(&tmp_sbuf);
msgpack_packer_init(&tmp_pck, &tmp_sbuf, msgpack_sbuffer_write);
msgpack_pack_map(&tmp_pck, map_size);

msgpack_pack_str(&tmp_pck, time_key_len);
msgpack_pack_str_body(&tmp_pck, time_key, time_key_len);
msgpack_pack_str(&tmp_pck, token_end-in_buf);
Expand Down
7 changes: 2 additions & 5 deletions src/multiline/flb_ml_parser_cri.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include <fluent-bit/multiline/flb_ml.h>
#include <fluent-bit/multiline/flb_ml_parser.h>

//Reverting change for fuzz test...
#define FLB_ML_CRI_REGEX \
"^(?<time>.+?) (?<stream>stdout|stderr) (?<_p>F|P) (?<log>.*)$"
#define FLB_ML_CRI_TIME \
"%Y-%m-%dT%H:%M:%S.%L%z"

Expand All @@ -33,8 +30,8 @@ static struct flb_parser *cri_parser_create(struct flb_config *config)
struct flb_parser *p;

p = flb_parser_create("_ml_cri", /* parser name */
"regex", //"cri", /* backend type */
FLB_ML_CRI_REGEX, //NULL, /* regex */
"cri", /* backend type */
NULL, /* regex */
FLB_FALSE, /* skip_empty */
FLB_ML_CRI_TIME, /* time format */
"time", /* time key */
Expand Down

0 comments on commit 9030e20

Please sign in to comment.