Skip to content

Commit e254a37

Browse files
committed
Fix review comments
- Add line to NEWS - Test more values for writable file handles - Fallback to zend_constants if curl_easy_option_by_id fails
1 parent 39fce02 commit e254a37

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ PHP NEWS
107107
and CURL_SEEKFUNC_CANTSEEK constants, letting libcurl rewind a streamed
108108
request body to resend it on a redirect, multi-pass authentication or a
109109
retried reused connection. (GrahamCampbell)
110+
. Improved cURL option validation errors to include the option name.
111+
(Sjoerd Langkemper)
110112

111113
- Date:
112114
. Update timelib to 2022.17. (Derick)

ext/curl/interface.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ ZEND_DECLARE_MODULE_GLOBALS(curl)
6464

6565
// php_curl_option_get_name(CURLOPT_HTTPHEADER) -> "HTTPHEADER"
6666
static const char * php_curl_option_get_name(zend_long option) {
67+
6768
#if LIBCURL_VERSION_NUM >= 0x074900
6869
const struct curl_easyoption * opt = curl_easy_option_by_id(option);
6970
if (EXPECTED(opt != NULL)) {
7071
return opt->name;
7172
}
72-
#else
73+
#endif
74+
7375
const char prefix[] = "CURLOPT_";
7476
const size_t prefix_len = sizeof(prefix) - 1;
7577
zend_string *key;
@@ -86,7 +88,6 @@ static const char * php_curl_option_get_name(zend_long option) {
8688
return ZSTR_VAL(key) + prefix_len;
8789
}
8890
} ZEND_HASH_FOREACH_END();
89-
#endif
9091
return "UNKNOWN_OPTION";
9192
}
9293

ext/curl/tests/bug48207.phpt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,17 @@ $tempfile = tempnam(sys_get_temp_dir(), 'CURL_FILE_HANDLE');
3636
$fp = fopen($tempfile, "r"); // Opening 'fubar' with the incorrect readonly flag
3737

3838
$ch = curl_init($url);
39-
try {
40-
curl_setopt($ch, CURLOPT_FILE, $fp);
41-
} catch (ValueError $exception) {
42-
echo $exception->getMessage() . "\n";
39+
40+
foreach ([
41+
CURLOPT_FILE,
42+
CURLOPT_WRITEHEADER,
43+
CURLOPT_STDERR,
44+
] as $option) {
45+
try {
46+
curl_setopt($ch, $option, $fp);
47+
} catch (ValueError $exception) {
48+
echo $exception->getMessage(), "\n";
49+
}
4350
}
4451

4552
curl_exec($ch);
@@ -48,5 +55,7 @@ isset($tempname) and is_file($tempname) and @unlink($tempname);
4855
?>
4956
--EXPECT--
5057
curl_setopt(): The file handle provided for CURLOPT_FILE must be writable
58+
curl_setopt(): The file handle provided for CURLOPT_WRITEHEADER must be writable
59+
curl_setopt(): The file handle provided for CURLOPT_STDERR must be writable
5160
Hello World!
5261
Hello World!

0 commit comments

Comments
 (0)