]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod/zstd: Do not re-use size_t for ret
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Sat, 30 Nov 2024 16:53:49 +0000 (10:53 -0600)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 6 Dec 2024 21:06:42 +0000 (13:06 -0800)
size_t is unsigned, while the function returns a negative number.
Instead of using `ret` for the return from ZSTD_decompress(), re-use
dst_size that should be the same as we passed in for that call since
it already checks for ZSTD_CONTENTSIZE_UNKNOWN and ZSTD_CONTENTSIZE_ERROR.

Even if it's not the same, it's more correct to use that value to
assign to file->size to avoid accessing uninitialized memory.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
libkmod/libkmod-file-zstd.c

index 9715000648567763e0e96490c3c1d94ad1d50e4e..220d77ab34d2a23a7385ad403a267495f1edd146 100644 (file)
 int kmod_file_load_zstd(struct kmod_file *file)
 {
        void *src_buf = MAP_FAILED, *dst_buf = NULL;
-       size_t src_size, dst_size, ret;
+       size_t src_size, dst_size;
        unsigned long long frame_size;
        struct stat st;
+       int ret;
 
        if (fstat(file->fd, &st) < 0) {
                ret = -errno;
@@ -64,9 +65,9 @@ int kmod_file_load_zstd(struct kmod_file *file)
                goto out;
        }
 
-       ret = ZSTD_decompress(dst_buf, dst_size, src_buf, src_size);
-       if (ZSTD_isError(ret)) {
-               ERR(file->ctx, "zstd: %s\n", ZSTD_getErrorName(ret));
+       dst_size = ZSTD_decompress(dst_buf, dst_size, src_buf, src_size);
+       if (ZSTD_isError(dst_size)) {
+               ERR(file->ctx, "zstd: %s\n", ZSTD_getErrorName(dst_size));
                ret = -EINVAL;
                goto out;
        }