diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-02 00:00:36 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-02 00:01:07 +0100 |
commit | c5830bdf6558edbc567d7c5dce1ff8059049e202 (patch) | |
tree | 74bdcea96383de159d406b3ce56623b8bd653f22 | |
parent | 8ae386bf195c6ea53232bacd2eb8cf26676962e4 (diff) | |
download | busybox-w32-c5830bdf6558edbc567d7c5dce1ff8059049e202.tar.gz busybox-w32-c5830bdf6558edbc567d7c5dce1ff8059049e202.tar.bz2 busybox-w32-c5830bdf6558edbc567d7c5dce1ff8059049e202.zip |
modprobe/insmod: fix parameter quoting
function old new delta
parse_cmdline_module_options 102 157 +55
modprobe_main 657 662 +5
insmod_main 68 70 +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 62/0) Total: 62 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | modutils/insmod.c | 2 | ||||
-rw-r--r-- | modutils/modprobe.c | 2 | ||||
-rw-r--r-- | modutils/modutils.c | 32 | ||||
-rw-r--r-- | modutils/modutils.h | 2 |
4 files changed, 28 insertions, 10 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c index e5b46f402..94e4e2863 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -59,7 +59,7 @@ int insmod_main(int argc UNUSED_PARAM, char **argv) | |||
59 | if (!filename) | 59 | if (!filename) |
60 | bb_show_usage(); | 60 | bb_show_usage(); |
61 | 61 | ||
62 | rc = bb_init_module(filename, parse_cmdline_module_options(argv)); | 62 | rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0)); |
63 | if (rc) | 63 | if (rc) |
64 | bb_error_msg("can't insert '%s': %s", filename, moderror(rc)); | 64 | bb_error_msg("can't insert '%s': %s", filename, moderror(rc)); |
65 | 65 | ||
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index e3bacac56..8d2ccc562 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -589,7 +589,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) | |||
589 | /* First argument is module name, rest are parameters */ | 589 | /* First argument is module name, rest are parameters */ |
590 | DBG("probing just module %s", *argv); | 590 | DBG("probing just module %s", *argv); |
591 | add_probe(argv[0]); | 591 | add_probe(argv[0]); |
592 | G.cmdline_mopts = parse_cmdline_module_options(argv); | 592 | G.cmdline_mopts = parse_cmdline_module_options(argv, /*quote_spaces:*/ 1); |
593 | } | 593 | } |
594 | 594 | ||
595 | /* Happens if all requested modules are already loaded */ | 595 | /* Happens if all requested modules are already loaded */ |
diff --git a/modutils/modutils.c b/modutils/modutils.c index 415dbbe44..6187ca72f 100644 --- a/modutils/modutils.c +++ b/modutils/modutils.c | |||
@@ -62,7 +62,7 @@ char* FAST_FUNC filename2modname(const char *filename, char *modname) | |||
62 | return modname; | 62 | return modname; |
63 | } | 63 | } |
64 | 64 | ||
65 | char* FAST_FUNC parse_cmdline_module_options(char **argv) | 65 | char* FAST_FUNC parse_cmdline_module_options(char **argv, int quote_spaces) |
66 | { | 66 | { |
67 | char *options; | 67 | char *options; |
68 | int optlen; | 68 | int optlen; |
@@ -70,13 +70,31 @@ char* FAST_FUNC parse_cmdline_module_options(char **argv) | |||
70 | options = xzalloc(1); | 70 | options = xzalloc(1); |
71 | optlen = 0; | 71 | optlen = 0; |
72 | while (*++argv) { | 72 | while (*++argv) { |
73 | options = xrealloc(options, optlen + 2 + strlen(*argv) + 2); | 73 | const char *fmt; |
74 | /* Spaces handled by "" pairs, but no way of escaping quotes */ | 74 | const char *var; |
75 | //TODO: module-init-tools version 3.11.1 quotes only value: | 75 | const char *val; |
76 | //it generates var="val with spaces", not "var=val with spaces" | 76 | |
77 | //(and it won't quote var *name* even if it has spaces) | 77 | var = *argv; |
78 | optlen += sprintf(options + optlen, (strchr(*argv, ' ') ? "\"%s\" " : "%s "), *argv); | 78 | options = xrealloc(options, optlen + 2 + strlen(var) + 2); |
79 | fmt = "%.*s%s "; | ||
80 | val = strchrnul(var, '='); | ||
81 | if (quote_spaces) { | ||
82 | /* | ||
83 | * modprobe (module-init-tools version 3.11.1) compat: | ||
84 | * quote only value: | ||
85 | * var="val with spaces", not "var=val with spaces" | ||
86 | * (note: var *name* is not checked for spaces!) | ||
87 | */ | ||
88 | if (*val) { /* has var=val format. skip '=' */ | ||
89 | val++; | ||
90 | if (strchr(val, ' ')) | ||
91 | fmt = "%.*s\"%s\" "; | ||
92 | } | ||
93 | } | ||
94 | optlen += sprintf(options + optlen, fmt, (int)(val - var), var, val); | ||
79 | } | 95 | } |
96 | /* Remove trailing space. Disabled */ | ||
97 | /* if (optlen != 0) options[optlen-1] = '\0'; */ | ||
80 | return options; | 98 | return options; |
81 | } | 99 | } |
82 | 100 | ||
diff --git a/modutils/modutils.h b/modutils/modutils.h index 863bc26d3..5f059c716 100644 --- a/modutils/modutils.h +++ b/modutils/modutils.h | |||
@@ -21,7 +21,7 @@ void replace(char *s, char what, char with) FAST_FUNC; | |||
21 | char *replace_underscores(char *s) FAST_FUNC; | 21 | char *replace_underscores(char *s) FAST_FUNC; |
22 | int string_to_llist(char *string, llist_t **llist, const char *delim) FAST_FUNC; | 22 | int string_to_llist(char *string, llist_t **llist, const char *delim) FAST_FUNC; |
23 | char *filename2modname(const char *filename, char *modname) FAST_FUNC; | 23 | char *filename2modname(const char *filename, char *modname) FAST_FUNC; |
24 | char *parse_cmdline_module_options(char **argv) FAST_FUNC; | 24 | char *parse_cmdline_module_options(char **argv, int quote_spaces) FAST_FUNC; |
25 | 25 | ||
26 | /* insmod for 2.4 and modprobe's options (insmod 2.6 has no options at all): */ | 26 | /* insmod for 2.4 and modprobe's options (insmod 2.6 has no options at all): */ |
27 | #define INSMOD_OPTS \ | 27 | #define INSMOD_OPTS \ |