[PATCH 1/1] makedevs: set path size to match linux
Denys Vlasenko
vda.linux at googlemail.com
Thu Jul 6 00:04:15 UTC 2017
On Tue, Jun 27, 2017 at 3:20 PM, Kang-Che Sung <explorer09 at 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!
More information about the busybox
mailing list