From d27a3152bd00e503187b0dcd18583bbf9822dbf0 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 6 Jul 2018 15:29:15 +0200 Subject: [PATCH] fix generate_transaction_id() --- miniupnpd/upnpstun.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/miniupnpd/upnpstun.c b/miniupnpd/upnpstun.c index 3ffe245..2f6b71c 100644 --- a/miniupnpd/upnpstun.c +++ b/miniupnpd/upnpstun.c @@ -45,10 +45,18 @@ static int delete_filter_rule(const char * ifname, unsigned short port, int prot /* Generate random STUN Transaction Id */ static void generate_transaction_id(unsigned char transaction_id[12]) { - int i; + size_t i, n; + long value; - for (i = 0; i < 12; ++i) - transaction_id[i] = random()%255; + i = 0; + while (i < 12) { + value = random(); + n = sizeof(value); + if (i + n > 12) + n = 12 - i; + memcpy(transaction_id + i, &value, n); + i += n; + } } /* Create and fill STUN Binding Request */