From: Adenilson Cavalcanti Date: Fri, 17 May 2024 20:37:55 +0000 (-0700) Subject: [fix] Add check on failed allocation in legacy/zstd_v06 X-Git-Tag: v1.5.7^2~120^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1872688e0adb630e8710cb3d17846ca49f596e46;p=thirdparty%2Fzstd.git [fix] Add check on failed allocation in legacy/zstd_v06 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. --- diff --git a/lib/legacy/zstd_v06.c b/lib/legacy/zstd_v06.c index 00d6ef79a..3a8bd0c93 100644 --- a/lib/legacy/zstd_v06.c +++ b/lib/legacy/zstd_v06.c @@ -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; }