From 31067d75e602e56fcae2c331553d0ab2c1eae3bc Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Wed, 13 Nov 2024 23:32:55 +0100 Subject: [PATCH] libkmod: Fix file error handling regression The propagation of errors from loading function through errno must make sure that errno is positive, otherwise errors are not correctly spotted. Signed-off-by: Tobias Stoeckmann --- libkmod/libkmod-file-zstd.c | 1 + libkmod/libkmod-file.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libkmod/libkmod-file-zstd.c b/libkmod/libkmod-file-zstd.c index 098d1074..97150006 100644 --- a/libkmod/libkmod-file-zstd.c +++ b/libkmod/libkmod-file-zstd.c @@ -67,6 +67,7 @@ int kmod_file_load_zstd(struct kmod_file *file) ret = ZSTD_decompress(dst_buf, dst_size, src_buf, src_size); if (ZSTD_isError(ret)) { ERR(file->ctx, "zstd: %s\n", ZSTD_getErrorName(ret)); + ret = -EINVAL; goto out; } diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index 828522ec..89f74641 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -67,7 +67,7 @@ struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) err = kmod_file_load_contents(file); if (err) { - errno = err; + errno = -err; return NULL; }