From 1eabf13577bfb2c440eb93851173fe01ed9d0ba9 Mon Sep 17 00:00:00 2001 From: modric Date: Sat, 19 Nov 2022 11:22:14 +0800 Subject: [PATCH] sudo_mmap_strdup_v1: Fix potential NULL pointer deref --- lib/util/mmap_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/util/mmap_alloc.c b/lib/util/mmap_alloc.c index df3d4cbcc2..cd678a07c5 100644 --- a/lib/util/mmap_alloc.c +++ b/lib/util/mmap_alloc.c @@ -116,8 +116,10 @@ sudo_mmap_strdup_v1(const char *str) return NULL; } newstr = sudo_mmap_alloc_v1(len + 1); - memcpy(newstr, str, len); - newstr[len] = '\0'; + if (newstr != NULL) { + memcpy(newstr, str, len); + newstr[len] = '\0'; + } return newstr; }