[Openmp-commits] [PATCH] D112174: [OpenMP] Fix possible NULL dereference

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Oct 21 06:19:52 PDT 2021

protze.joachim added a comment.

  start_tool = (ompt_start_tool_t)dlsym(h, "ompt_start_tool");

I find the dlsym description confusing:

> The function dlsym() [...] return[s] the address where that symbol is loaded into memory.

If the symbol is loaded into memory, how can the address be NULL?

> Since the value of the symbol could actually be NULL (so that a NULL return from dlsym() need not indicate an error)

With `if (!start_tool)` we check the address of the symbol to be !=NULL, not the symbol itself.

If the symbol is NULL, but the function returns the address to the symbol, I would need to dereference the address to see the NULL, i.e. `*start_tool` == NULL? What do I miss here?

Comment at: openmp/runtime/src/ompt-general.cpp:349
+        dlerror(); // Clear any existing error
         start_tool = (ompt_start_tool_t)dlsym(h, "ompt_start_tool");
I would argue, that dlerror is cleared at this point, but calling the function anyways should not harm.

  rG LLVM Github Monorepo



More information about the Openmp-commits mailing list