-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bpo-28503: _crypt: fix implicit declaration of crypt(), use crypt_r() if available. #4691
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
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
The '_crypt' module provides a binding to the C crypt(3) function. It is used by the crypt.crypt() function. Looking at the C code, there are a couple of things we can improve: - Because crypt() only depends on primitive C types, we currently get away with calling it without it being declared. Ensure that we include <unistd.h>, which is the POSIX header file declaring this. - The disadvantage of crypt() is that it's thread-unsafe. Systems like Linux and recent versions of FreeBSD nowadays provide crypt_r() as a replacement. This function allows you to pass in a 'crypt_data' object that will hold the resulting string for you. Extend the code to use this function when available. This patch is actually needed to make this module build on CloudABI (https://mail.python.org/pipermail/python-dev/2016-July/145708.html). CloudABI's C library doesn't provide any thread-unsafe functions, meaning that crypt_r() is the only way you can crypt passwords.
c23bc2b
to
f8e4237
Compare
@@ -2679,6 +2679,7 @@ AC_MSG_RESULT($SHLIBS) | |||
AC_CHECK_LIB(sendfile, sendfile) | |||
AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV | |||
AC_CHECK_LIB(dld, shl_load) # Dynamic linking for HP-UX | |||
AC_CHECK_LIB(crypt, crypt) # crypt() on Linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAVE_LIBCRYPT
created by this doesn't seem to be used in Modules/_cryptmodule.c
. I recently tried to use AC_CHECK_LIB
for the same use case, but there were some comments concerning the test program created by autotools. I end up using the following approach:
AC_MSG_CHECKING(for uuid_generate_time_safe)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <uuid/uuid.h>]], [[
#ifndef uuid_generate_time_safe
void *x = uuid_generate_time_safe
#endif
]])],
[AC_DEFINE(HAVE_UUID_GENERATE_TIME_SAFE, 1, Define if uuid_generate_time_safe() exists.)
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
Any progress on this? It appears to be needed for the latest Fedora, where they switched to gcc 8.1. |
Are you sure? Undeclared functions are assumed a return type of This PR does fix that problem. |
Moreover, it's getting urgent, as there are plans to remove
Building (on a 64-bit Linux) with Perhaps it makes sense to split this PR into two - one making |
Linking with |
#11373 is a modern version of this. I'm waiting on the CI over there before merging it, but rather than anyone spending time updating and addressing conflicts in this one I'm just going to close it. Our overall concepts are similar. I did the configure.ac check a bit differently to account for |
The '_crypt' module provides a binding to the C crypt(3) function. It is
used by the crypt.crypt() function.
Looking at the C code, there are a couple of things we can improve:
Because crypt() only depends on primitive C types, we currently get
away with calling it without it being declared. Ensure that we include
<unistd.h>, which is the POSIX header file declaring this.
The disadvantage of crypt() is that it's thread-unsafe. Systems like
Linux and recent versions of FreeBSD nowadays provide crypt_r() as a
replacement. This function allows you to pass in a 'crypt_data' object
that will hold the resulting string for you. Extend the code to use
this function when available.
This patch is actually needed to make this module build on CloudABI
(https://mail.python.org/pipermail/python-dev/2016-July/145708.html).
CloudABI's C library doesn't provide any thread-unsafe functions,
meaning that crypt_r() is the only way you can crypt passwords.
https://bugs.python.org/issue28503