[Openmp-commits] [openmp] ab43ab6 - [OpenMP] Fix use of uninitialized Dl_info when dladdr fails in ompd_init (#193643)

via Openmp-commits openmp-commits at lists.llvm.org
Tue Apr 28 14:05:38 PDT 2026


Author: Mark Zhuang
Date: 2026-04-29T05:05:33+08:00
New Revision: ab43ab6158a19f60048cdbc77fe645ae61de0bae

URL: https://github.com/llvm/llvm-project/commit/ab43ab6158a19f60048cdbc77fe645ae61de0bae
DIFF: https://github.com/llvm/llvm-project/commit/ab43ab6158a19f60048cdbc77fe645ae61de0bae.diff

LOG: [OpenMP] Fix use of uninitialized Dl_info when dladdr fails in ompd_init (#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

Added: 
    

Modified: 
    openmp/runtime/src/ompd-specific.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/ompd-specific.cpp b/openmp/runtime/src/ompd-specific.cpp
index c4018789eb5b2..dadfb26e0e125 100644
--- a/openmp/runtime/src/ompd-specific.cpp
+++ b/openmp/runtime/src/ompd-specific.cpp
@@ -88,10 +88,8 @@ 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