diff --git a/src/config_format/flb_cf_fluentbit.c b/src/config_format/flb_cf_fluentbit.c index f973654ad35..c34f6974c44 100644 --- a/src/config_format/flb_cf_fluentbit.c +++ b/src/config_format/flb_cf_fluentbit.c @@ -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 */ @@ -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; @@ -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; @@ -501,10 +502,11 @@ 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; @@ -512,15 +514,21 @@ static int read_config(struct flb_cf *cf, struct local_ctx *ctx, } #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