From: Lucas De Marchi Date: Sat, 30 Nov 2024 16:53:49 +0000 (-0600) Subject: libkmod/zstd: Do not re-use size_t for ret X-Git-Tag: v34~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fd66bee036301e47c354798d0816cf72534ccc3;p=thirdparty%2Fkmod.git libkmod/zstd: Do not re-use size_t for ret 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 Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/262 --- diff --git a/libkmod/libkmod-file-zstd.c b/libkmod/libkmod-file-zstd.c index 97150006..220d77ab 100644 --- a/libkmod/libkmod-file-zstd.c +++ b/libkmod/libkmod-file-zstd.c @@ -22,9 +22,10 @@ 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; }