From 0288126d9cc0d061766e37cbbaabaa78aff3aff5 Mon Sep 17 00:00:00 2001 From: Kevin Svetlitski Date: Thu, 11 May 2023 14:20:30 -0700 Subject: [PATCH] Fix possible `NULL` pointer dereference from `mallctl("prof.prefix", ...)` Static analysis flagged this issue. Here is a minimal program which causes a segfault within Jemalloc: ``` #include const char *malloc_conf = "prof:true"; int main() { mallctl("prof.prefix", NULL, NULL, NULL, 0); } ``` Fixed by checking if `prefix` is `NULL`. --- src/prof_sys.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/prof_sys.c b/src/prof_sys.c index 3f7196f8..3cbb3a85 100644 --- a/src/prof_sys.c +++ b/src/prof_sys.c @@ -749,6 +749,9 @@ bool prof_prefix_set(tsdn_t *tsdn, const char *prefix) { cassert(config_prof); ctl_mtx_assert_held(tsdn); + if (prefix == NULL) { + return true; + } malloc_mutex_lock(tsdn, &prof_dump_filename_mtx); if (prof_prefix == NULL) { malloc_mutex_unlock(tsdn, &prof_dump_filename_mtx);