]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Remove random() from a potential htonl() macro which could call it more than once.
authorRoy Marples <roy@marples.name>
Wed, 4 May 2016 13:05:52 +0000 (13:05 +0000)
committerRoy Marples <roy@marples.name>
Wed, 4 May 2016 13:05:52 +0000 (13:05 +0000)
ipv4ll.c

index 8203433a59934144af6f86e79fb660a051a51f82..14427be5c892dcab9e87f98c1e16e1e20a9e2308 100644 (file)
--- a/ipv4ll.c
+++ b/ipv4ll.c
@@ -58,12 +58,15 @@ ipv4ll_pick_addr(const struct arp_state *astate)
        setstate(istate->randomstate);
 
        do {
+               long r;
+
                /* RFC 3927 Section 2.1 states that the first 256 and
                 * last 256 addresses are reserved for future use.
                 * See ipv4ll_start for why we don't use arc4_random. */
                /* coverity[dont_call] */
+               r = random();
                addr.s_addr = ntohl(LINKLOCAL_ADDR |
-                   ((uint32_t)(random() % 0xFD00) + 0x0100));
+                   ((uint32_t)(r % 0xFD00) + 0x0100));
 
                /* No point using a failed address */
                if (addr.s_addr == astate->failed.s_addr)