[PATCH] ar: read_num(): fix reading fields using the entire width
Peter Korsgaard
jacmet at sunsite.dk
Wed Sep 11 11:43:55 UTC 2013
>>>>> "walter" == walter harms <wharms at 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
More information about the busybox
mailing list