[PATCH] modprobe: handle module arguments containing spaces

Denys Vlasenko vda.linux at googlemail.com
Wed Sep 9 12:56:30 UTC 2015


On Mon, Sep 7, 2015 at 10:18 PM, Peter Korsgaard <peter at korsgaard.com> wrote:
> Modprobe wasn't correctly parsing module arguments containing spaces from
> /proc/cmdline - E.G. module.property="some text".
>
> Extend the parsing to correctly handle quoted text.
>
> Signed-off-by: Peter Korsgaard <peter at korsgaard.com>
> ---
> Adding the helper in modprobe.c isn't really nice, but I don't see any
> existing infrastructure for this in libbb.
>
>  modutils/modprobe.c | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/modutils/modprobe.c b/modutils/modprobe.c
> index 996de40..bea7b0e 100644
> --- a/modutils/modprobe.c
> +++ b/modutils/modprobe.c
> @@ -348,6 +348,36 @@ static const char *humanly_readable_name(struct module_entry *m)
>         return m->probed_name ? m->probed_name : m->modname;
>  }
>
> +/* like strsep(&stringp, "\n\t ") but handles quotes (") */
> +static char *split_quotes(char **stringp)
> +{
> +       char *s, *start = *stringp;
> +
> +       if (!start)
> +               return NULL;
> +
> +       for (s = start; ; s++) {
> +               switch (*s) {
> +               case '"':
> +                       s = strchr(s + 1, '"'); /* find trailing quote */
> +                       if (*s != '\0')
> +                               s++; /* skip trailing quote */

bug, you must be thinking about using strchrnul().


> +                       /* fall through */
> +
> +               case '\0':
> +               case '\n':
> +               case '\t':
> +               case ' ':
> +                       if (*s != '\0') {
> +                               *s++ = '\0';
> +                               *stringp = s;
> +                       } else
> +                               *stringp = NULL;
> +                       return start;
> +               }
> +       }
> +}
> +
>  static char *parse_and_add_kcmdline_module_options(char *options, const char *modulename)
>  {
>         char *kcmdline_buf;
> @@ -359,7 +389,7 @@ static char *parse_and_add_kcmdline_module_options(char *options, const char *mo
>                 return options;
>
>         kcmdline = kcmdline_buf;
> -       while ((kptr = strsep(&kcmdline, "\n\t ")) != NULL) {
> +       while ((kptr = split_quotes(&kcmdline)) != NULL) {
>                 char *after_modulename = is_prefixed_with(kptr, modulename);
>                 if (!after_modulename || *after_modulename != '.')
>                         continue;


Applied with small changes, thanks


More information about the busybox mailing list