[Openmp-commits] [openmp] c704b25 - [OpenMP] libomp: Fix possible NULL dereference.

via Openmp-commits openmp-commits at lists.llvm.org
Wed Oct 27 06:54:54 PDT 2021


Author: AndreyChurbanov
Date: 2021-10-27T16:54:44+03:00
New Revision: c704b25b449418217f2e3ee41c100f3ee9a59e4c

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

LOG: [OpenMP] libomp: Fix possible NULL dereference.

According to dlsym description, the value of symbol could be NULL,
and there is no error in this case. Thus dlerror will also return NULL in
this case. We need to check the value returned by dlerror before printing it.

Differential Revision: https://reviews.llvm.org/D112174

Added: 
    

Modified: 
    openmp/runtime/src/ompt-general.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/ompt-general.cpp b/openmp/runtime/src/ompt-general.cpp
index 89cd23ce34a03..c4a9be8753b76 100644
--- a/openmp/runtime/src/ompt-general.cpp
+++ b/openmp/runtime/src/ompt-general.cpp
@@ -346,9 +346,16 @@ ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
         OMPT_VERBOSE_INIT_CONTINUED_PRINT("Success. \n");
         OMPT_VERBOSE_INIT_PRINT("Searching for ompt_start_tool in %s... ",
                                 fname);
+        dlerror(); // Clear any existing error
         start_tool = (ompt_start_tool_t)dlsym(h, "ompt_start_tool");
         if (!start_tool) {
-          OMPT_VERBOSE_INIT_CONTINUED_PRINT("Failed: %s\n", dlerror());
+          char *error = dlerror();
+          if (error != NULL) {
+            OMPT_VERBOSE_INIT_CONTINUED_PRINT("Failed: %s\n", error);
+          } else {
+            OMPT_VERBOSE_INIT_CONTINUED_PRINT("Failed: %s\n",
+                                              "ompt_start_tool = NULL");
+          }
         } else
 #elif KMP_OS_WINDOWS
       OMPT_VERBOSE_INIT_PRINT("Opening %s... ", fname);


        


More information about the Openmp-commits mailing list