Skip to content

Commit 78d5783

Browse files
author
Julien Pauli
committed
Backported bug #71144 (Segmentation fault when using cURL with ZTS)
1 parent 0be13d2 commit 78d5783

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ext/curl/interface.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,9 @@ static void _php_curl_set_default_options(php_curl *ch)
19251925
curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
19261926
curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header);
19271927
curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
1928+
#if !defined(ZTS)
19281929
curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
1930+
#endif
19291931
curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
19301932
curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */
19311933

@@ -2263,7 +2265,14 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
22632265
return 1;
22642266
}
22652267
#endif
2268+
# if defined(ZTS)
2269+
if (option == CURLOPT_DNS_USE_GLOBAL_CACHE) {
2270+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled");
2271+
return 1;
2272+
}
2273+
# endif
22662274
error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
2275+
22672276
break;
22682277
case CURLOPT_SAFE_UPLOAD:
22692278
convert_to_long_ex(zvalue);

ext/curl/tests/bug71144.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #71144 (Sementation fault when using cURL with ZTS)
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
<?php if (!PHP_ZTS) { print "skip only for zts build"; } ?>
6+
--FILE--
7+
<?php
8+
$ch = curl_init();
9+
var_dump(curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, 1));
10+
?>
11+
--EXPECTF--
12+
Warning: curl_setopt(): CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled in %sbug71144.php on line %d
13+
bool(false)

0 commit comments

Comments
 (0)