]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Verify absolute path creation
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 16 Aug 2024 21:49:18 +0000 (23:49 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Sat, 17 Aug 2024 17:14:16 +0000 (12:14 -0500)
If a relative path is supplied, the conversion to an absolute path can
fail, e.g. if current working directory does not exist anymore.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/79
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod.c
tools/depmod.c

index 0478093f4ef097bda4232442bf9100d1afa0df37..61efe2d646e8ba9f33e48efc2e7e07c91c2bc7fa 100644 (file)
@@ -288,6 +288,10 @@ KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname,
        ctx->log_priority = LOG_ERR;
 
        ctx->dirname = get_kernel_release(dirname);
+       if (ctx->dirname == NULL) {
+               ERR(ctx, "could not retrieve directory\n");
+               goto fail;
+       }
 
        /* environment overwrites config */
        env = secure_getenv("KMOD_LOG");
index f2f3c7c17b94e50b87ea0d0f9f4e0f74e85ad4d6..8ba8ee406778bcac5be4a3178100caa0deb2ddca 100644 (file)
@@ -2937,11 +2937,19 @@ static int do_depmod(int argc, char *argv[])
                        if (root)
                                free(root);
                        root = path_make_absolute_cwd(optarg);
+                       if (root == NULL) {
+                               ERR("invalid image path %s\n", optarg);
+                               goto cmdline_failed;
+                       }
                        break;
                case 'o':
                        if (out_root)
                                free(out_root);
                        out_root = path_make_absolute_cwd(optarg);
+                       if (out_root == NULL) {
+                               ERR("invalid output directory %s\n", optarg);
+                               goto cmdline_failed;
+                       }
                        break;
                case 'C': {
                        size_t bytes = sizeof(char *) * (n_config_paths + 2);