Skip to content

Commit 01bd37c

Browse files
committed
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 <fujimoto@ceptord.net>
1 parent f952970 commit 01bd37c

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

plugins/out_gelf/gelf.c

+2-15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <fluent-bit/flb_gzip.h>
2525
#include <fluent-bit/flb_utils.h>
2626
#include <fluent-bit/flb_network.h>
27+
#include <fluent-bit/flb_random.h>
2728
#include <msgpack.h>
2829

2930
#include <stdio.h>
@@ -321,8 +322,6 @@ static void cb_gelf_flush(const void *data, size_t bytes,
321322
static int cb_gelf_init(struct flb_output_instance *ins, struct flb_config *config,
322323
void *data)
323324
{
324-
int ret;
325-
int fd;
326325
const char *tmp;
327326
struct flb_out_gelf_config *ctx = NULL;
328327

@@ -408,21 +407,9 @@ static int cb_gelf_init(struct flb_output_instance *ins, struct flb_config *conf
408407
}
409408

410409
/* init random seed */
411-
fd = open("/dev/urandom", O_RDONLY);
412-
if (fd == -1) {
410+
if (flb_randombytes((unsigned char *) &ctx->seed, sizeof(int))) {
413411
ctx->seed = time(NULL);
414412
}
415-
else {
416-
unsigned int val;
417-
ret = read(fd, &val, sizeof(val));
418-
if (ret > 0) {
419-
ctx->seed = val;
420-
}
421-
else {
422-
ctx->seed = time(NULL);
423-
}
424-
close(fd);
425-
}
426413
srand(ctx->seed);
427414

428415
ctx->fd = -1;

0 commit comments

Comments
 (0)