Skip to content

Fix ctypes usage with Python 3.9 #3000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

vincentbernat
Copy link
Contributor

There is a regression in Python 3.9 with the find_library()
function:

>>> import ctypes.util
>>> ctypes.util.find_library("libc")
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/lib/python3.9/ctypes/util.py", line 341, in find_library
     _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
   File "/usr/lib/python3.9/ctypes/util.py", line 147, in _findLib_gcc
     if not _is_elf(file):
   File "/usr/lib/python3.9/ctypes/util.py", line 99, in _is_elf
     with open(filename, 'br') as thefile:
 FileNotFoundError: [Errno 2] No such file or directory: b'liblibc.a'

A workaround is to use find_library("c") instead. It also works in
older versions of Python and that's already what's used in
contrib/isotp.py.

Python issue reported here:
https://bugs.python.org/issue42580

Signed-off-by: Vincent Bernat [email protected]

There is a regression in Python 3.9 with the `find_library()`
function:

    >>> import ctypes.util
    >>> ctypes.util.find_library("libc")
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
       File "/usr/lib/python3.9/ctypes/util.py", line 341, in find_library
         _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
       File "/usr/lib/python3.9/ctypes/util.py", line 147, in _findLib_gcc
         if not _is_elf(file):
       File "/usr/lib/python3.9/ctypes/util.py", line 99, in _is_elf
         with open(filename, 'br') as thefile:
     FileNotFoundError: [Errno 2] No such file or directory: b'liblibc.a'

A workaround is to use `find_library("c")` instead. It also works in
older versions of Python and that's already what's used in
`contrib/isotp.py`.

Python issue reported here:
 https://bugs.python.org/issue42580

Signed-off-by: Vincent Bernat <[email protected]>
Copy link
Member

@guedou guedou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@guedou
Copy link
Member

guedou commented Dec 7, 2020

On which operating system did you get the issue? It works fine on macOS with Python3.9.

@vincentbernat
Copy link
Contributor Author

On Debian unstable. If it helps, note find_library() does not expect to get a name prefixed with lib:

https://docs.python.org/3/library/ctypes.html

Try to find a library and return a pathname. name is the library name without any prefix like lib, suffix like .so, .dylib or version number (this is the form used for the posix linker option -l). If no library can be found, returns None.

@p-l-
Copy link
Member

p-l- commented Dec 7, 2020

Python 3.9.0 (under ArchLinux) gets no error:

>>> import ctypes.util
>>> ctypes.util.find_library("libc")

But:

>>> ctypes.util.find_library("c")
'libc.so.6'

Which is probably what one expects.

@gpotter2 gpotter2 merged commit 46fa40f into secdev:master Dec 11, 2020
vincentbernat added a commit to vincentbernat/trex-core that referenced this pull request Oct 17, 2022
The embedded version of Scapy is using `find_library("libc")` which is
incorrect. This does not work anymore with Python 3.9. This should use
`find_library("c")` instead (which also works for older versions). See
secdev/scapy#3000 for more details.

Anoher option would be to upgrade Scapy to 2.4.5, where this bug is
fixed.

Signed-off-by: Vincent Bernat <[email protected]>
hhaim pushed a commit to cisco-system-traffic-generator/trex-core that referenced this pull request Oct 20, 2022
The embedded version of Scapy is using `find_library("libc")` which is
incorrect. This does not work anymore with Python 3.9. This should use
`find_library("c")` instead (which also works for older versions). See
secdev/scapy#3000 for more details.

Anoher option would be to upgrade Scapy to 2.4.5, where this bug is
fixed.

Signed-off-by: Vincent Bernat <[email protected]>
hhaim pushed a commit to cisco-system-traffic-generator/trex-core that referenced this pull request Mar 22, 2023
The embedded version of Scapy is using `find_library("libc")` which is
incorrect. This does not work anymore with Python 3.9. This should use
`find_library("c")` instead (which also works for older versions). See
secdev/scapy#3000 for more details.

Anoher option would be to upgrade Scapy to 2.4.5, where this bug is
fixed.

Signed-off-by: Vincent Bernat <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants