aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2024-02-12 17:23:07 +0000
committerLucas De Marchi <lucas.de.marchi@gmail.com>2024-04-30 12:33:52 -0500
commit81e5c797d0620ce719dee84a89878b8eca762340 (patch)
treed997442e1bca1b858b71980dce4720eae86f0748
parentad15892394740763f2c13cefb5fd908bdb966517 (diff)
downloadkmod-81e5c797d0620ce719dee84a89878b8eca762340.tar.gz
libkmod: propagate {zstd,xz,zlib}_load errors
Propagate any errors during decompression further up the call stack. Without this we could easily pass NULL as mem to init_module(2). Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
-rw-r--r--libkmod/libkmod-file.c15
-rw-r--r--libkmod/libkmod-internal.h2
-rw-r--r--libkmod/libkmod-module.c4
3 files changed, 15 insertions, 6 deletions
diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c
index 8a0336f..3a79464 100644
--- a/libkmod/libkmod-file.c
+++ b/libkmod/libkmod-file.c
@@ -381,10 +381,17 @@ static int load_reg(struct kmod_file *file)
struct kmod_elf *kmod_file_get_elf(struct kmod_file *file)
{
+ int err;
+
if (file->elf)
return file->elf;
- kmod_file_load_contents(file);
+ err = kmod_file_load_contents(file);
+ if (err) {
+ errno = err;
+ return NULL;
+ }
+
file->elf = kmod_elf_new(file->memory, file->size);
return file->elf;
}
@@ -460,13 +467,13 @@ error:
/*
* Callers should just check file->memory got updated
*/
-void kmod_file_load_contents(struct kmod_file *file)
+int kmod_file_load_contents(struct kmod_file *file)
{
if (file->memory)
- return;
+ return 0;
/* The load functions already log possible errors. */
- file->load(file);
+ return file->load(file);
}
void *kmod_file_get_contents(const struct kmod_file *file)
diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h
index 26a7e28..3bc6e11 100644
--- a/libkmod/libkmod-internal.h
+++ b/libkmod/libkmod-internal.h
@@ -160,7 +160,7 @@ bool kmod_module_is_builtin(struct kmod_module *mod) __attribute__((nonnull(1)))
/* libkmod-file.c */
struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2)));
struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) __attribute__((nonnull(1)));
-void kmod_file_load_contents(struct kmod_file *file) __attribute__((nonnull(1)));
+int kmod_file_load_contents(struct kmod_file *file) __attribute__((nonnull(1)));
void *kmod_file_get_contents(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
off_t kmod_file_get_size(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
enum kmod_file_compression_type kmod_file_get_compression(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 585da41..1e43482 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -903,7 +903,9 @@ static int do_init_module(struct kmod_module *mod, unsigned int flags,
off_t size;
int err;
- kmod_file_load_contents(mod->file);
+ err = kmod_file_load_contents(mod->file);
+ if (err)
+ return err;
if (flags & (KMOD_INSERT_FORCE_VERMAGIC | KMOD_INSERT_FORCE_MODVERSION)) {
elf = kmod_file_get_elf(mod->file);