Correctly skip interface indexes larger than 256
PATCH 1/1 Correctly skip interface indexes larger than 256
fscanf line probably copied from kernel printf, but printf specifies the minimal field widwth and scanf the maximal field width.
printf (3) manual:
Quoted 4 lines
Each conversion specification is introduced by the character %, and ends with a conversion specifier. In between there may be (in this order) zero or more flags, an optional minimum field width, an optional precision and an optional length modifier.
fscanf manual:
Quoted 7 lines
Each conversion specification in format begins with either the character '%' or the character sequence "%n$" (see below for the distinction) followed by:
* An optional '*' assignment-suppression character:
scanf()reads input as directed by the conversion specification, but discards the input. No corresponding pointer argument is required, and this specification is not included in the count of successful assignments returned byscanf().
[...]
Quoted 7 lines
* An optional decimal integer which specifies the maximum field width. Reading of characters stops either when this maximum is reached or when a nonmatching character is found, whichever happens first. Most conversions discard initial white space characters (the exceptions are noted below), and these discarded characters don't count toward the maximum field width. String input conversions store a terminating null byte ('\0') to mark the end of the input; the maximum field width does not include this terminator.
--- user/shared/shared_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
user/shared/shared_main.c +1 -1
@@ -186,7 +186,7 @@ int have_ip_ipv6(const char *ip)while (fscanf (if_inet6, - X32(08) X32(08) X32(08) X32(08) " %*02x %*02x %*02x %*02x %s", + X32(08) X32(08) X32(08) X32(08) " %*x %*x %*x %*x %s", b, b +1 , b +2 , b +3 , name) >0 ) {for (i =0 ; i <4 ; i++) addr6.s6_addr32[i] =cpu_to_be32 (b[i]);
Signature · 1 line
1.9.1
user/shared/shared_main.c int have_ip_ipv6(const char *ip) · line 189
Quoted 2 lines · Dirk Tilger
user/shared/shared_main.c +1
-1- X32(08) X32(08) X32(08) X32(08) " %*02x %*02x %*02x %*02x %s", + X32(08) X32(08) X32(08) X32(08) " %*x %*x %*x %*x %s",
Are numbers larger than 0xff even possible?
We read the string from "/proc/net/if_inet6", and to me it looks like the interfaces limits the input range to values <= 255 [1].
Would be great if you could provide an example where it really makes a difference, i.e. how to get lager values than 255 in the ignored format string positions.
Regards, rck
[1] http://www.tldp.org/HOWTO/Linux+IPv6-HOWTO/proc-net.html
Quoted 6 lines · Roland Kammerer
user/shared/shared_main.c int have_ip_ipv6(const char *ip) · line 189
Quoted 2 lines · Dirk Tilger
user/shared/shared_main.c +1
-1- X32(08) X32(08) X32(08) X32(08) " %*02x %*02x %*02x %*02x %s", + X32(08) X32(08) X32(08) X32(08) " %*x %*x %*x %*x %s",Are numbers larger than
0xffeven possible?
Yes, it is possible...
Thank you Dirk for the hint and the patch. Applied to our internal repo.
Regards, rck