]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[fix] Add check on failed allocation in legacy/zstd_v06 4050/head
authorAdenilson Cavalcanti <cavalcantii@chromium.org>
Fri, 17 May 2024 20:37:55 +0000 (13:37 -0700)
committerAdenilson Cavalcanti <cavalcantii@chromium.org>
Fri, 17 May 2024 22:40:28 +0000 (15:40 -0700)
As reported by Ben Hawkes in #4026, a failure to allocate a zstd context
would lead to a dereference of a NULL pointer due to a missing check
on the returned result of ZSTDv06_createDCtx().

This patch fix the issue by adding a check for valid returned pointer.

lib/legacy/zstd_v06.c

index 00d6ef79aa250ace8caac09c0782189bcb746533..3a8bd0c93641d208b333f2caa457ec19d0be132f 100644 (file)
@@ -3919,6 +3919,10 @@ ZBUFFv06_DCtx* ZBUFFv06_createDCtx(void)
     if (zbd==NULL) return NULL;
     memset(zbd, 0, sizeof(*zbd));
     zbd->zd = ZSTDv06_createDCtx();
+    if (zbd->zd==NULL) {
+        ZBUFFv06_freeDCtx(zbd); /* avoid leaking the context */
+        return NULL;
+    }
     zbd->stage = ZBUFFds_init;
     return zbd;
 }