[Openmp-commits] [openmp] [OpenMP] Fix use of uninitialized Dl_info when dladdr fails in ompd_init (PR #193643)
Mark Zhuang via Openmp-commits
openmp-commits at lists.llvm.org
Wed Apr 22 19:05:03 PDT 2026
https://github.com/zqb-all created https://github.com/llvm/llvm-project/pull/193643
When dladdr() fails, dl_info is left uninitialized. The code printed the error but then fell through to unconditionally call strrchr(dl_info.dli_fname, '/'), accessing an uninitialized pointer -- typically NULL on the stack -- causing a SIGSEGV.
Fix by turning the second 'if' into 'else if', so the path-extraction block is only reached when dladdr() succeeded and dl_info is valid.
Assisted-by: Claude Sonnet 4.6
>From 63e7f6ab75d6154a9033eae6b0b6b53066a2d47c Mon Sep 17 00:00:00 2001
From: Mark Zhuang <mark.zhuang at spacemit.com>
Date: Thu, 23 Apr 2026 09:10:33 +0800
Subject: [PATCH] [OpenMP] Fix use of uninitialized Dl_info when dladdr fails
in ompd_init
When dladdr() fails, dl_info is left uninitialized.
The code printed the error but then fell through to unconditionally
call strrchr(dl_info.dli_fname, '/'), accessing an uninitialized
pointer -- typically NULL on the stack -- causing a SIGSEGV.
Fix by turning the second 'if' into 'else if', so the path-extraction
block is only reached when dladdr() succeeded and dl_info is valid.
Assisted-by: Claude Sonnet 4.6
---
openmp/runtime/src/ompd-specific.cpp | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/openmp/runtime/src/ompd-specific.cpp b/openmp/runtime/src/ompd-specific.cpp
index c4018789eb5b2..b0503f1d2ad1f 100644
--- a/openmp/runtime/src/ompd-specific.cpp
+++ b/openmp/runtime/src/ompd-specific.cpp
@@ -88,10 +88,9 @@ void ompd_init() {
int ret = dladdr((void *)ompd_init, &dl_info);
if (!ret) {
fprintf(stderr, "%s\n", dlerror());
- }
- int lib_path_length;
- if (strrchr(dl_info.dli_fname, '/')) {
- lib_path_length = strrchr(dl_info.dli_fname, '/') - dl_info.dli_fname;
+ } else if (strrchr(dl_info.dli_fname, '/')) {
+ int lib_path_length =
+ strrchr(dl_info.dli_fname, '/') - dl_info.dli_fname;
libname =
(char *)malloc(lib_path_length + 12 /*for '/libompd.so' and '\0'*/);
strncpy(libname, dl_info.dli_fname, lib_path_length);
More information about the Openmp-commits
mailing list