From: Tobias Stoeckmann Date: Wed, 23 Oct 2024 21:52:05 +0000 (+0200) Subject: tools: Use options_from_array in insmod X-Git-Tag: v34~181 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7155cf1db5a7879ffa9b2710e50628da3c32627a;p=thirdparty%2Fkmod.git tools: Use options_from_array in insmod Adjust arguments of options_from_array to avoid skipping the first array entry because that's not intuitive based on its function name. Fixes insmod's handling of module options given as quoted command line arguments. Signed-off-by: Tobias Stoeckmann Link: https://github.com/kmod-project/kmod/pull/204 Signed-off-by: Lucas De Marchi --- diff --git a/tools/insmod.c b/tools/insmod.c index 74669a93..f7916b5f 100644 --- a/tools/insmod.c +++ b/tools/insmod.c @@ -64,10 +64,9 @@ static int do_insmod(int argc, char *argv[]) struct kmod_module *mod; const char *filename; char *opts = NULL; - size_t optslen = 0; int verbose = LOG_ERR; int use_syslog = 0; - int i, c, r = 0; + int c, r = 0; const char *null_config = NULL; unsigned int flags = 0; @@ -112,23 +111,9 @@ static int do_insmod(int argc, char *argv[]) goto end; } - for (i = optind + 1; i < argc; i++) { - size_t len = strlen(argv[i]); - void *tmp = realloc(opts, optslen + len + 2); - if (tmp == NULL) { - ERR("out of memory\n"); - r = EXIT_FAILURE; - goto end; - } - opts = tmp; - if (optslen > 0) { - opts[optslen] = ' '; - optslen++; - } - memcpy(opts + optslen, argv[i], len); - optslen += len; - opts[optslen] = '\0'; - } + r = options_from_array(argv + optind + 1, argc - optind - 1, &opts); + if (r < 0) + goto end; ctx = kmod_new(NULL, &null_config); if (!ctx) { diff --git a/tools/modprobe.c b/tools/modprobe.c index 5c2c53a6..ec66e6fc 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -953,7 +953,7 @@ static int do_modprobe(int argc, char **orig_argv) err = insmod_all(ctx, args, nargs); else { char *opts; - err = options_from_array(args, nargs, &opts); + err = options_from_array(args + 1, nargs - 1, &opts); if (err == 0) { err = insmod(ctx, args[0], opts); free(opts); diff --git a/tools/opt.c b/tools/opt.c index 2447f51b..944209bd 100644 --- a/tools/opt.c +++ b/tools/opt.c @@ -15,7 +15,7 @@ int options_from_array(char **args, int nargs, char **output) size_t optslen = 0; int i, err = 0; - for (i = 1; i < nargs; i++) { + for (i = 0; i < nargs; i++) { size_t len = strlen(args[i]); size_t qlen = 0; const char *value;