Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ctypes: We do not correctly handle NULL dlsym() return values #126554

Closed
Labels
3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirtopic-ctypestype-bugAn unexpected behavior, bug, or error
@grgalex

Description

@grgalex

Bug report

Bug description:

The man(3) page fordlsym() states:

In unusual cases (see NOTES) the value of the symbol  could  actually  beNULL. Therefore, a NULL return from dlsym() need not indicate an error.The correct way to distinguish an error from a symbol whose value is NULLis  to  call  dlerror(3) to clear any old error conditions, then call dl‐sym(), and then call dlerror(3) again, saving its  return  value  into  avariable, and check whether this saved value is not NULL.

As such, there can be cases where a call todlsym returnsNULL, while no error has been encountered and the string thatdlerror() returns has not been (re)set.

Currently, (https://github.com/python/cpython/blob/main/Modules/_ctypes/_ctypes.c#L970) we do:

<...>address= (void*)dlsym(handle,name);if (!address) {#ifdef__CYGWIN__<snipWindowsstuff>#elsePyErr_SetString(PyExc_ValueError,dlerror());<...>

Ifdlsym() returnsNULL, then by callingdlerror() we pass eitherNULL or a previous, unconsumed error string toPyErr_SetString.

In the context ofctypes, aNULL return bydlsym() might indeed always be considered an error.

To correctly express this, we should:

  • Calldlerror() beforedlsym(), to clear any previous error
  • Calldlerror() afterdlsym(), to see ifdlsym() encountered any error
    • Ifdlerror() returns a non-NULL value, then pass its result toPyErr_SetString
    • Ifdlerror() returns NULL, then check ifaddress is NULL, and if so, pass a custom error string toPyErr_SetString.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirtopic-ctypestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp