Skip to content

Commit

Permalink
out_es: check if converted_size is 0 to prevent SIGFPE(#3905)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Aug 13, 2021
1 parent b2aba7e commit 9d212bf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions plugins/out_es/es_bulk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9d212bf

Please sign in to comment.