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 25, 2024
1 parent 7ab84ab commit 24261f4
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 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 All @@ -106,7 +112,7 @@ int flb_parser_cri_do(struct flb_parser *parser,
token_end = token_end + 2; /* indicator + a space */

/* Log */
end_of_line = strpbrk(token_end, "\n");
end_of_line = strpbrk(token_end, "\r\n");
if (end_of_line == NULL ) {
end_of_line = in_buf+in_size;
}
Expand Down

0 comments on commit 24261f4

Please sign in to comment.