[PATCHv5 03/23] lib: zstd: fix null-deref in ZSTD_createCDict_advanced2()

Sergey Senozhatsky posted 23 patches 1 year, 7 months ago
[PATCHv5 03/23] lib: zstd: fix null-deref in ZSTD_createCDict_advanced2()
Posted by Sergey Senozhatsky 1 year, 7 months ago
ZSTD_createCDict_advanced2() must ensure that
ZSTD_createCDict_advanced_internal() has successfully
allocated cdict.  customMalloc() may be called under
low memory condition and may be unable to allocate
workspace for cdict.

Cc: Nick Terrell <terrelln@fb.com>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 lib/zstd/compress/zstd_compress.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/zstd/compress/zstd_compress.c b/lib/zstd/compress/zstd_compress.c
index c1c316e9e289..e48c73880477 100644
--- a/lib/zstd/compress/zstd_compress.c
+++ b/lib/zstd/compress/zstd_compress.c
@@ -5336,6 +5336,8 @@ ZSTD_CDict* ZSTD_createCDict_advanced2(
                         dictLoadMethod, cctxParams.cParams,
                         cctxParams.useRowMatchFinder, cctxParams.enableDedicatedDictSearch,
                         customMem);
+    if (!cdict)
+        return NULL;
 
     if (ZSTD_isError( ZSTD_initCDict_internal(cdict,
                                     dict, dictSize,
-- 
2.45.2.803.g4e1b14247a-goog
Re: [PATCH v5 03/23] lib: zstd: fix null-deref in ZSTD_createCDict_advanced2()
Posted by Markus Elfring 1 year, 7 months ago
> ZSTD_createCDict_advanced2() must ensure that
> ZSTD_createCDict_advanced_internal() has successfully
> allocated cdict.  customMalloc() may be called under
> low memory condition and may be unable to allocate
> workspace for cdict.

* Please improve such a change description with imperative wordings.
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10-rc6#n94

* Would you like to use the term “null pointer dereference” (in the summary phrase)?


Regards,
Markus