aboutsummaryrefslogtreecommitdiff
path: root/modutils/modutils.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-02-02 00:00:36 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-02 00:01:07 +0100
commitc5830bdf6558edbc567d7c5dce1ff8059049e202 (patch)
tree74bdcea96383de159d406b3ce56623b8bd653f22 /modutils/modutils.c
parent8ae386bf195c6ea53232bacd2eb8cf26676962e4 (diff)
downloadbusybox-c5830bdf6558edbc567d7c5dce1ff8059049e202.tar.gz
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>
Diffstat (limited to 'modutils/modutils.c')
-rw-r--r--modutils/modutils.c32
1 files changed, 25 insertions, 7 deletions
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)
return modname;
}
-char* FAST_FUNC parse_cmdline_module_options(char **argv)
+char* FAST_FUNC parse_cmdline_module_options(char **argv, int quote_spaces)
{
char *options;
int optlen;
@@ -70,13 +70,31 @@ char* FAST_FUNC parse_cmdline_module_options(char **argv)
options = xzalloc(1);
optlen = 0;
while (*++argv) {
- options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
- /* Spaces handled by "" pairs, but no way of escaping quotes */
-//TODO: module-init-tools version 3.11.1 quotes only value:
-//it generates var="val with spaces", not "var=val with spaces"
-//(and it won't quote var *name* even if it has spaces)
- optlen += sprintf(options + optlen, (strchr(*argv, ' ') ? "\"%s\" " : "%s "), *argv);
+ const char *fmt;
+ const char *var;
+ const char *val;
+
+ var = *argv;
+ options = xrealloc(options, optlen + 2 + strlen(var) + 2);
+ fmt = "%.*s%s ";
+ val = strchrnul(var, '=');
+ if (quote_spaces) {
+ /*
+ * modprobe (module-init-tools version 3.11.1) compat:
+ * quote only value:
+ * var="val with spaces", not "var=val with spaces"
+ * (note: var *name* is not checked for spaces!)
+ */
+ if (*val) { /* has var=val format. skip '=' */
+ val++;
+ if (strchr(val, ' '))
+ fmt = "%.*s\"%s\" ";
+ }
+ }
+ optlen += sprintf(options + optlen, fmt, (int)(val - var), var, val);
}
+ /* Remove trailing space. Disabled */
+ /* if (optlen != 0) options[optlen-1] = '\0'; */
return options;
}