From 11011dc93691989513ff2101c221ea15dab5658a Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 5 Dec 2016 11:52:35 +0100 Subject: [PATCH] write_kafka plugin: Use 32bit random number when formatting a random key. Previously, negative numbers would be truncated to "ffffffff" by the buffer length on architectures where longs are 64 bit. Fixes: #2074 --- src/write_kafka.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/write_kafka.c b/src/write_kafka.c index dba09c03..1712a478 100644 --- a/src/write_kafka.c +++ b/src/write_kafka.c @@ -31,6 +31,7 @@ #include "utils_cmd_putval.h" #include "utils_format_graphite.h" #include "utils_format_json.h" +#include "utils_random.h" #include #include @@ -88,7 +89,7 @@ static uint32_t kafka_hash(const char *keydata, size_t keylen) { #define KAFKA_RANDOM_KEY_BUFFER \ (char[KAFKA_RANDOM_KEY_SIZE]) { "" } static char *kafka_random_key(char buffer[static KAFKA_RANDOM_KEY_SIZE]) { - ssnprintf(buffer, KAFKA_RANDOM_KEY_SIZE, "%08lX", (unsigned long)mrand48()); + ssnprintf(buffer, KAFKA_RANDOM_KEY_SIZE, "%08" PRIX32, cdrand_u()); return buffer; } -- 2.11.0