Heartbeat STABLE 1.2

changeset 2873:0e4a1b7a0045

[IPv6addr] Handle scanf failures in scan_if()
If for some reason the file being scanned is malformed, or
overflows one of the feilds for some reason, scanf will neither
return EOF nor fill in all of its parameters correctly. In the
case that I observed this resulted in an endless loop.

This simple fix just bails out in this case.
author Horms <horms@verge.net.au>
date Fri Apr 20 11:31:15 2007 +0900 (2 years ago)
parents 629ac0cd3ea9
children 44daddd0f03e
files heartbeat/resource.d/IPv6addr.c
line diff
1.1 --- a/heartbeat/resource.d/IPv6addr.c Fri Apr 20 11:31:15 2007 +0900 1.2 +++ b/heartbeat/resource.d/IPv6addr.c Fri Apr 20 11:31:15 2007 +0900 1.3 @@ -378,16 +378,26 @@ 1.4 } 1.5 1.6 /* Loop for each entry */ 1.7 - while ( fscanf(f,"%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n", 1.8 - addr6p[0], addr6p[1], addr6p[2], addr6p[3], 1.9 - addr6p[4], addr6p[5], addr6p[6], addr6p[7], 1.10 - &if_idx, &plen, &scope, &dad_status, devname) != EOF){ 1.11 - 1.12 + while (1) { 1.13 int i; 1.14 int n; 1.15 int s; 1.16 gboolean same = TRUE; 1.17 1.18 + i = fscanf(f, 1.19 + "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n", 1.20 + addr6p[0], addr6p[1], addr6p[2], addr6p[3], 1.21 + addr6p[4], addr6p[5], addr6p[6], addr6p[7], 1.22 + &if_idx, &plen, &scope, &dad_status, devname); 1.23 + if (i == EOF) { 1.24 + break; 1.25 + } 1.26 + else if (i != 13) { 1.27 + cl_log(LOG_INFO, "Error parsing %s, " 1.28 + "perhaps the format has changed\n", IF_INET6); 1.29 + break; 1.30 + } 1.31 + 1.32 sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s", 1.33 addr6p[0], addr6p[1], addr6p[2], addr6p[3], 1.34 addr6p[4], addr6p[5], addr6p[6], addr6p[7]);