]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[ldm] Fix ZSTD_c_ldmHashRateLog bounds check 2819/head
authorNick Terrell <terrelln@fb.com>
Fri, 8 Oct 2021 18:17:40 +0000 (11:17 -0700)
committerNick Terrell <terrelln@fb.com>
Fri, 8 Oct 2021 18:17:40 +0000 (11:17 -0700)
There is no minimum value check, so the parameter could be negative.
Switch to the standard pattern of using `BOUNDCHECK()`.

The bug was reported by Dan Carpenter and found by Smatch static
checker.

https://lore.kernel.org/all/20211008063704.GA5370@kili/

lib/compress/zstd_compress.c

index 9e2fb3193321ed1d411d498c0e5ea492de96914e..edfd7eb07356fae068ef00b044216db20354845f 100644 (file)
@@ -866,8 +866,8 @@ size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* CCtxParams,
         return CCtxParams->ldmParams.bucketSizeLog;
 
     case ZSTD_c_ldmHashRateLog :
-        RETURN_ERROR_IF(value > ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN,
-                        parameter_outOfBound, "Param out of bounds!");
+        if (value!=0)   /* 0 ==> default */
+            BOUNDCHECK(ZSTD_c_ldmHashRateLog, value);
         CCtxParams->ldmParams.hashRateLog = value;
         return CCtxParams->ldmParams.hashRateLog;