From 01bd37c791b0447da0456b7af6f304b41cab0766 Mon Sep 17 00:00:00 2001 From: Fujimoto Seiji Date: Tue, 29 Sep 2020 14:38:38 +0900 Subject: [PATCH] out_gelf: Port the random seed generation to Windows Windows does not have /dev/urandom. For this reason, it was always using a less secure value (= UNIX time) as an entropy source. Use flb_randombytes() to use a good entropy source, and thus, reduce the possibility of message collision. Signed-off-by: Fujimoto Seiji --- plugins/out_gelf/gelf.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/plugins/out_gelf/gelf.c b/plugins/out_gelf/gelf.c index f965d03b29d..a42a2d54ac3 100644 --- a/plugins/out_gelf/gelf.c +++ b/plugins/out_gelf/gelf.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -321,8 +322,6 @@ static void cb_gelf_flush(const void *data, size_t bytes, static int cb_gelf_init(struct flb_output_instance *ins, struct flb_config *config, void *data) { - int ret; - int fd; const char *tmp; struct flb_out_gelf_config *ctx = NULL; @@ -408,21 +407,9 @@ static int cb_gelf_init(struct flb_output_instance *ins, struct flb_config *conf } /* init random seed */ - fd = open("/dev/urandom", O_RDONLY); - if (fd == -1) { + if (flb_randombytes((unsigned char *) &ctx->seed, sizeof(int))) { ctx->seed = time(NULL); } - else { - unsigned int val; - ret = read(fd, &val, sizeof(val)); - if (ret > 0) { - ctx->seed = val; - } - else { - ctx->seed = time(NULL); - } - close(fd); - } srand(ctx->seed); ctx->fd = -1;