Skip to content

Commit

Permalink
Check if we actually get data from urandom for mac generation. Fixes:…
Browse files Browse the repository at this point in the history
… CID 1042358

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Jul 5, 2013
1 parent 23b7e68 commit d43a633
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/usb_moded-mac.c
Expand Up @@ -27,13 +27,19 @@
static void random_ether_addr(unsigned char *addr)
{
FILE *random;
size_t count = 0;

random = fopen("/dev/urandom", "r");
fread(addr, 1, 6, random);
count = fread(addr, 1, 6, random);
fclose(random);

addr [0] &= 0xfe; /* clear multicast bit */
addr [0] |= 0x02; /* set local assignment bit (IEEE802) */
if(count > 0 )
{
addr [0] &= 0xfe; /* clear multicast bit */
addr [0] |= 0x02; /* set local assignment bit (IEEE802) */
}
else
log_warning("MAC generation failed!\n");
}

void generate_random_mac (void)
Expand Down

0 comments on commit d43a633

Please sign in to comment.