On Thu, Jul 6, 2017 at 3:31 AM, Kang-Che Sung <explore...@gmail.com> wrote: > On Thu, Jul 6, 2017 at 8:04 AM, Denys Vlasenko <vda.li...@googlemail.com> > wrote: >> On Tue, Jun 27, 2017 at 3:20 PM, Kang-Che Sung <explore...@gmail.com> wrote: >>> Hello. Can I suggest another way? >>> How about modifying the `line` buffer so it can be used directly as the >>> name, >>> and avoid the malloc problem or STRINGIFY(PATH_MAX) altogether. >>> >>> My suggestion (warning, this code is not tested): >>> >>> --- a/miscutils/makedevs.c >>> +++ b/miscutils/makedevs.c >>> @@ -209,23 +209,27 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) >>> unsigned increment = 0; >>> unsigned start = 0; >>> char name[41]; >>> + int name_len; >>> char user[41]; >>> char group[41]; >>> - char *full_name = name; >>> + char *full_name; >>> uid_t uid; >>> gid_t gid; >>> >>> linenum = parser->lineno; >>> >>> - if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", >>> - name, &type, &mode, user, group, >>> + if ((1 > sscanf(line, "%*s%n %c %o %40s %40s %u %u %u %u %u", >>> + &name_len, &type, &mode, user, group, >>> &major, &minor, &start, &increment, &count)) >>> + || (PATH_MAX > name_len + 1) >>> || ((unsigned)(major | minor | start | count | increment) > 255) >>> ) { >>> bb_error_msg("invalid line %d: '%s'", linenum, line); >>> ret = EXIT_FAILURE; >>> continue; >>> } >>> + line[name_len] = '\0'; >>> + full_name = line; >> >> Good idea! >> >> Applied, thanks! > > Wait. I was not expecting the patch be applied directly. I was expecting it > be tested first.
I did test it. > I think my code has a bug: > If the line begins with whitespaces, the initial whitespaces will be included > in `full_name` while the original code won't. config_read() removes leading whitespace. _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox