]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
tools: Use options_from_array in insmod
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 23 Oct 2024 21:52:05 +0000 (23:52 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 24 Oct 2024 03:10:39 +0000 (22:10 -0500)
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 <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/204
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/insmod.c
tools/modprobe.c
tools/opt.c

index 74669a93b414ae2e0a1575f413730c8c4e4e5d5f..f7916b5f13c47434ee26e734468456d9ff916b0c 100644 (file)
@@ -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) {
index 5c2c53a6bae02928b0afa3be885dcee7286b1e8d..ec66e6fcbee7be88f97cff3e62b60cb29f74dabb 100644 (file)
@@ -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);
index 2447f51bbb2f58aa407be5acf0a014c2b675462d..944209bdef69a5d10316745a80950f31bc2941fb 100644 (file)
@@ -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;