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 13, 2023
1 parent 0b3294c commit 53a4996
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 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 @@ -418,6 +417,8 @@ static int read_config(struct flb_cf *cf, struct local_ctx *ctx,
char *val = NULL;
int val_len;
char *buf;
size_t bufsize = 4096;
long fpos = 0;
char tmp[PATH_MAX];
flb_sds_t section = NULL;
flb_sds_t indent = NULL;
Expand Down Expand Up @@ -486,7 +487,7 @@ static int read_config(struct flb_cf *cf, struct local_ctx *ctx,
#endif

/* 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 +502,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)) {
while (fgets(buf, bufsize, f)) {
#endif
len = strlen(buf);
if (len > 0 && buf[len - 1] == '\n') {
fpos += len;
buf[--len] = 0;
if (len && buf[len - 1] == '\r') {
buf[--len] = 0;
}
}
#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_error("failed to resize line buffer to %zu", bufsize);
flb_errno();
goto error;
}
/* return to the previous file position */
if (fseek(f, fpos, SEEK_SET) != 0) {
flb_errno();
goto error;
}
/* try again */
continue;
}
#endif

Expand Down

0 comments on commit 53a4996

Please sign in to comment.