Skip to content

Commit

Permalink
core: allow arbitrary lengths in read_config
Browse files Browse the repository at this point in the history
Signed-off-by: Thiago Padilha <[email protected]>
  • Loading branch information
tchrono committed Jul 12, 2023
1 parent 0b3294c commit 090f8fe
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/config_format/flb_cf_fluentbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#define PATH_MAX MAX_PATH
#endif

#define FLB_CF_BUF_SIZE 4096
#define FLB_CF_FILE_NUM_LIMIT 1000

/* indent checker return codes */
Expand Down Expand Up @@ -485,8 +484,9 @@ static int read_config(struct flb_cf *cf, struct local_ctx *ctx,
}
#endif

size_t bufsize = 4096;
/* Allocate temporal buffer to read file content */
buf = flb_malloc(FLB_CF_BUF_SIZE);
buf = flb_malloc(bufsize);
if (!buf) {
flb_errno();
goto error;
Expand All @@ -501,26 +501,33 @@ static int read_config(struct flb_cf *cf, struct local_ctx *ctx,
while (static_fgets(buf, FLB_CF_BUF_SIZE, in_data, &off)) {
#else
/* normal mode, read lines into a buffer */
while (fgets(buf, FLB_CF_BUF_SIZE, f)) {
long pos = 0;
while (fgets(buf, bufsize, f)) {
#endif
len = strlen(buf);
if (len > 0 && buf[len - 1] == '\n') {
buf[--len] = 0;
if (len && buf[len - 1] == '\r') {
buf[--len] = 0;
}
pos = ftell(f);
}
#ifndef FLB_HAVE_STATIC_CONF
else {
/*
* If we don't find a break line, validate if we got an EOF or not. No EOF
* means that the incoming string is not finished so we must raise an
* exception.
*/
if (!feof(f)) {
config_error(cfg_file, line, "length of content has exceeded limit");
/* resize the line buffer */
bufsize *= 2;
buf = flb_realloc(buf, bufsize);
if (!buf) {
flb_errno();
goto error;
}
/* return to the previous file position */
if (fseek(f, pos, SEEK_SET) != 0) {
flb_errno();
goto error;
}
/* try again */
continue;
}
#endif

Expand Down

0 comments on commit 090f8fe

Please sign in to comment.