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

Commit 2ecafd4

Browse files
authored
Remove curl OpenSSL locking for unsupported versions (#18784)
1 parent 484d435 commit 2ecafd4

File tree

2 files changed

+12
-86
lines changed

2 files changed

+12
-86
lines changed

‎ext/curl/config.m4‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ if test "$PHP_CURL" != "no"; then
1515
AC_MSG_RESULT([$CURL_SSL])
1616

1717
AS_IF([test "x$PHP_THREAD_SAFETY" = xyes && test "x$CURL_SSL" = xyes],
18-
[AC_CACHE_CHECK([whether libcurl is linked against old OpenSSL < 1.1],
19-
[php_cv_lib_curl_ssl], [
18+
[AC_CACHE_CHECK([whether libcurl is linked against a supported OpenSSL version],
19+
[php_cv_lib_curl_ssl_supported], [
2020
save_LIBS=$LIBS
2121
save_CFLAGS=$CFLAGS
2222
LIBS="$LIBS $CURL_SHARED_LIBADD"
@@ -34,17 +34,14 @@ if test "$PHP_CURL" != "no"; then
3434
3535
while(*ptr == ' ') ++ptr;
3636
int major, minor;
37-
if (sscanf(ptr, "OpenSSL/%d", &major) == 1) {
38-
if (major >= 3) {
39-
/* OpenSSL version 3 or later */
40-
return 4;
41-
}
42-
}
4337
if (sscanf(ptr, "OpenSSL/%d.%d", &major, &minor) == 2) {
44-
if (major > 1 || (major == 1 && minor >= 1)) {
45-
/* OpenSSL version 1.1 or later */
38+
/* Check for 1.1.1+ (including 1.1.1a, 1.1.1b, etc.) */
39+
if ((major > 1) || (major == 1 && minor == 1 && strncmp(ptr + 12, "1", 1) == 0)) {
40+
/* OpenSSL 1.1.1+ - supported */
4641
return 3;
4742
}
43+
/* OpenSSL 1.1.0 and earlier - unsupported */
44+
return 0;
4845
}
4946
if (strncasecmp(ptr, "OpenSSL", sizeof("OpenSSL")-1) == 0) {
5047
/* Old OpenSSL version */
@@ -56,18 +53,15 @@ if test "$PHP_CURL" != "no"; then
5653
/* No SSL support */
5754
return 1;
5855
])],
59-
[php_cv_lib_curl_ssl=yes],
60-
[php_cv_lib_curl_ssl=no],
61-
[php_cv_lib_curl_ssl=no])
56+
[php_cv_lib_curl_ssl_supported=no],
57+
[php_cv_lib_curl_ssl_supported=yes],
58+
[php_cv_lib_curl_ssl_supported=yes])
6259
LIBS=$save_LIBS
6360
CFLAGS=$save_CFLAGS
6461
])
6562
66-
AS_VAR_IF([php_cv_lib_curl_ssl], [yes], [
67-
AC_DEFINE([HAVE_CURL_OLD_OPENSSL], [1],
68-
[Define to 1 if libcurl is linked against old OpenSSL < 1.1.])
69-
PHP_SETUP_OPENSSL([CURL_SHARED_LIBADD],
70-
[AC_CHECK_HEADERS([openssl/crypto.h])])
63+
AS_VAR_IF([php_cv_lib_curl_ssl_supported], [no], [
64+
AC_MSG_ERROR([libcurl is linked against an unsupported OpenSSL version. OpenSSL 1.1.1 or later is required.])
7165
])
7266
])
7367

‎ext/curl/interface.c‎

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@
3939
#define HttpPost curl_httppost
4040
#endif
4141

42-
/* {{{ cruft for thread safe SSL crypto locks */
43-
#if defined(ZTS) && defined(HAVE_CURL_OLD_OPENSSL)
44-
# if defined(HAVE_OPENSSL_CRYPTO_H)
45-
# define PHP_CURL_NEED_OPENSSL_TSL
46-
# include <openssl/crypto.h>
47-
# else
48-
# warning \
49-
"libcurl was compiled with OpenSSL support, but configure could not find " \
50-
"openssl/crypto.h; thus no SSL crypto locking callbacks will be set, which may " \
51-
"cause random crashes on SSL requests"
52-
# endif
53-
#endif /* ZTS && HAVE_CURL_OLD_OPENSSL */
54-
/* }}} */
55-
5642
#include "zend_smart_str.h"
5743
#include "ext/standard/info.h"
5844
#include "ext/standard/file.h"
@@ -70,27 +56,6 @@
7056

7157
ZEND_DECLARE_MODULE_GLOBALS(curl)
7258

73-
#ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */
74-
static MUTEX_T *php_curl_openssl_tsl = NULL;
75-
76-
/* Locking callbacks are no longer used since OpenSSL 1.1. Mark the functions as unused to
77-
* avoid warnings due to this. */
78-
static ZEND_ATTRIBUTE_UNUSED void php_curl_ssl_lock(int mode, int n, const char * file, int line)
79-
{
80-
if (mode & CRYPTO_LOCK) {
81-
tsrm_mutex_lock(php_curl_openssl_tsl[n]);
82-
} else {
83-
tsrm_mutex_unlock(php_curl_openssl_tsl[n]);
84-
}
85-
}
86-
87-
static ZEND_ATTRIBUTE_UNUSED unsigned long php_curl_ssl_id(void)
88-
{
89-
return (unsigned long) tsrm_thread_id();
90-
}
91-
#endif
92-
/* }}} */
93-
9459
#define CAAL(s, v) add_assoc_long_ex(return_value, s, sizeof(s) - 1, (zend_long) v);
9560
#define CAAD(s, v) add_assoc_double_ex(return_value, s, sizeof(s) - 1, (double) v);
9661
#define CAAS(s, v) add_assoc_string_ex(return_value, s, sizeof(s) - 1, (char *) (v ? v : ""));
@@ -389,24 +354,6 @@ PHP_MINIT_FUNCTION(curl)
389354

390355
register_curl_symbols(module_number);
391356

392-
#ifdef PHP_CURL_NEED_OPENSSL_TSL
393-
if (!CRYPTO_get_id_callback()) {
394-
int i, c = CRYPTO_num_locks();
395-
396-
php_curl_openssl_tsl = malloc(c * sizeof(MUTEX_T));
397-
if (!php_curl_openssl_tsl) {
398-
return FAILURE;
399-
}
400-
401-
for (i = 0; i < c; ++i) {
402-
php_curl_openssl_tsl[i] = tsrm_mutex_alloc();
403-
}
404-
405-
CRYPTO_set_id_callback(php_curl_ssl_id);
406-
CRYPTO_set_locking_callback(php_curl_ssl_lock);
407-
}
408-
#endif
409-
410357
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
411358
return FAILURE;
412359
}
@@ -568,21 +515,6 @@ zend_result curl_cast_object(zend_object *obj, zval *result, int type)
568515
PHP_MSHUTDOWN_FUNCTION(curl)
569516
{
570517
curl_global_cleanup();
571-
#ifdef PHP_CURL_NEED_OPENSSL_TSL
572-
if (php_curl_openssl_tsl) {
573-
int i, c = CRYPTO_num_locks();
574-
575-
CRYPTO_set_id_callback(NULL);
576-
CRYPTO_set_locking_callback(NULL);
577-
578-
for (i = 0; i < c; ++i) {
579-
tsrm_mutex_free(php_curl_openssl_tsl[i]);
580-
}
581-
582-
free(php_curl_openssl_tsl);
583-
php_curl_openssl_tsl = NULL;
584-
}
585-
#endif
586518
UNREGISTER_INI_ENTRIES();
587519
return SUCCESS;
588520
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /