From 1872688e0adb630e8710cb3d17846ca49f596e46 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Fri, 17 May 2024 13:37:55 -0700 Subject: [PATCH] [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. --- lib/legacy/zstd_v06.c | 4 ++++ 1 file changed, 4 insertions(+) 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; } -- 2.47.2