From 3fff6824a0efee2ad67d7bd815f29e7b61e59184 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Mon, 9 Aug 2021 13:11:56 +0900 Subject: [PATCH] out_es: check if converted_size is 0 to prevent SIGFPE(#3905) We updated re-allocation logic(#3788). It tries to divide by converted_size. If converted_size is 0, it causes SIGFPE and exit code 136. Signed-off-by: Takahiro Yamashita --- plugins/out_es/es_bulk.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/out_es/es_bulk.c b/plugins/out_es/es_bulk.c index 6d6f383c2bf..95f4e5cd8ac 100644 --- a/plugins/out_es/es_bulk.c +++ b/plugins/out_es/es_bulk.c @@ -78,11 +78,17 @@ int es_bulk_append(struct es_bulk *bulk, char *index, int i_len, * 1. rest of msgpack data size * 2. ratio from bulk json size and processed msgpack size. */ - append_size = (whole_size - converted_size) /* rest of size to convert */ - * (bulk->size / converted_size); /* = json size / msgpack size */ - if (append_size < ES_BULK_CHUNK) { - /* append at least ES_BULK_CHUNK size */ + if (converted_size == 0) { + /* converted_size = 0 causes div/0 */ + flb_debug("[out_es] converted_size is 0"); append_size = ES_BULK_CHUNK; + } else { + append_size = (whole_size - converted_size) /* rest of size to convert */ + * (bulk->size / converted_size); /* = json size / msgpack size */ + if (append_size < ES_BULK_CHUNK) { + /* append at least ES_BULK_CHUNK size */ + append_size = ES_BULK_CHUNK; + } } ptr = flb_realloc(bulk->ptr, bulk->size + append_size); if (!ptr) {