[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] ar: read_num(): fix reading fields using the entire width
From:       Peter Korsgaard <jacmet () sunsite ! dk>
Date:       2013-09-11 11:43:55
Message-ID: 87zjrjr3b8.fsf () dell ! be ! 48ers ! dk
[Download RAW message or body]

>>>>> "walter" == walter harms <wharms@bfs.de> writes:

 walter> Am 10.09.2013 11:52, schrieb Peter Korsgaard:
 >> ar fields are fixed length text strings (padded with spaces). Ensure
 >> bb_strtou doesn't read past the field in case the full width is used.
 >> 
 >> The fields are only read once, so the simplest/smallest solution to me
 >> seems to be to just pass the length to read_num() and then zero terminate
 >> the string before passing it to bb_strtou. This does mean that the fields
 >> MUST be read in reverse order, so some minor reshuffling was needed.
 >> 
 >> -static unsigned read_num(const char *str, int base)
 >> +/* WARNING: Clobbers str[len], so fields must be read in reverse order! */
 >> +static unsigned read_num(char *str, int base, int len)
 >> {
 >> +	int err;
 >> +
 >> +	/* ar fields are fixed length text strings (padded with spaces).
 >> +	 * Ensure bb_strtou doesn't read past the field in case the full
 >> +	 * width is used. */
 >> +	str[len] = 0;
 >> +

 walter> should this be len-1 ?

No. We want to terminate the string so we don't read past len ([0..len-1]).

-- 
Bye, Peter Korsgaard
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic