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

Andrey Churbanov via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Oct 25 11:01:54 PDT 2021


AndreyChurbanov added a comment.

In D112174#3077754 <https://reviews.llvm.org/D112174#3077754>, @protze.joachim wrote:

>   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?

The description of dlsym has a note (https://man7.org/linux/man-pages/man3/dlsym.3.html):

  There are several scenarios when the address of a global symbol
  is NULL.  For example, a symbol can be placed at zero address by
  the linker, via a linker script or with --defsym command-line
  option.  Undefined weak symbols also have NULL value.  Finally,
  the symbol value may be the result of a GNU indirect function
  (IFUNC) resolver function that returns NULL as the resolved
  value.  In the latter case, dlsym() also returns NULL without
  error.

So, theoretically both dlsym and following dlerror can return NULL.
I don't see a problem in using verbose recommended way of checking functions return values,
just to be on the safe side.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112174/new/

https://reviews.llvm.org/D112174



More information about the Openmp-commits mailing list