Skip to content

Commit

Permalink
multiline: cri parser, ensure minimum line length after finding time
Browse files Browse the repository at this point in the history
Signed-off-by: ryanohnemus <[email protected]>
  • Loading branch information
ryanohnemus committed Sep 24, 2024
1 parent 7ab84ab commit e14075d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/flb_parser_cri.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ int flb_parser_cri_do(struct flb_parser *parser,
}
time_key_len = strlen(time_key);

/* Prepare new outgoing buffer */
msgpack_sbuffer_init(&tmp_sbuf);
msgpack_packer_init(&tmp_pck, &tmp_sbuf, msgpack_sbuffer_write);
msgpack_pack_map(&tmp_pck, map_size);

/* Time */
token_end = strpbrk(in_buf, CRI_SPACE_DELIM);
if (token_end == NULL) {
msgpack_sbuffer_destroy(&tmp_sbuf);

/* after we find 'time' field (which is variable length),
* we also check that we have enough room for static size fields
* - 1 space + stream (6 chars) + 1 space
* - _p (1 char) + 1 space
* = 10 characters past 'time' field
*/
if (token_end == NULL || token_end-in_buf+10 > in_size) {
return -1;
}
token_end = token_end + 1; /* time + a space */

/* 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,
Expand All @@ -79,8 +84,9 @@ int flb_parser_cri_do(struct flb_parser *parser,

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-1);
msgpack_pack_str_body(&tmp_pck, in_buf, token_end-in_buf-1);
msgpack_pack_str(&tmp_pck, token_end-in_buf);
msgpack_pack_str_body(&tmp_pck, in_buf, token_end-in_buf);
token_end = token_end + 1; /* time + a space */

/* Stream */
if (!(!strncmp(token_end, "stdout ", 7) || !strncmp(token_end, "stderr ", 7))) {
Expand Down

0 comments on commit e14075d

Please sign in to comment.