Skip to content

Commit e2b1709

Browse files
committed
Show curl option name in error message
Use curl_easy_option_by_id to retrieve the name of the option, and also show the name of the option in the case where strings contain a null byte. curl_easy_option_by_id simplifies the code, but was introduced in curl 7.73.0, so this also bumps the minimum version of curl. 7.73.0 was released in 2020, so I think that's acceptable. Showing the option name is especially useful when using curl_setopt_array. A user may specify many options, and this change makes it clear which option is wrong exactly.
1 parent 02ca74f commit e2b1709

3 files changed

Lines changed: 8 additions & 39 deletions

File tree

ext/curl/interface.c

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ ZEND_DECLARE_MODULE_GLOBALS(curl)
6565
static zend_result php_curl_option_str(php_curl *ch, zend_long option, const char *str, const size_t len)
6666
{
6767
if (zend_char_has_nul_byte(str, len)) {
68-
zend_value_error("%s(): cURL option must not contain any null bytes", get_active_function_name());
68+
const struct curl_easyoption *option_info = curl_easy_option_by_id(option);
69+
zend_value_error("%s(): cURL option CURLOPT_%s must not contain any null bytes", get_active_function_name(), option_info->name);
6970
return FAILURE;
7071
}
7172

@@ -2085,43 +2086,10 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
20852086
HashTable *ph;
20862087
zend_string *val, *tmp_val;
20872088
struct curl_slist *slist = NULL;
2088-
const char *name = NULL;
2089-
2090-
switch (option) {
2091-
case CURLOPT_HTTPHEADER:
2092-
name = "CURLOPT_HTTPHEADER";
2093-
break;
2094-
case CURLOPT_QUOTE:
2095-
name = "CURLOPT_QUOTE";
2096-
break;
2097-
case CURLOPT_HTTP200ALIASES:
2098-
name = "CURLOPT_HTTP200ALIASES";
2099-
break;
2100-
case CURLOPT_POSTQUOTE:
2101-
name = "CURLOPT_POSTQUOTE";
2102-
break;
2103-
case CURLOPT_PREQUOTE:
2104-
name = "CURLOPT_PREQUOTE";
2105-
break;
2106-
case CURLOPT_TELNETOPTIONS:
2107-
name = "CURLOPT_TELNETOPTIONS";
2108-
break;
2109-
case CURLOPT_MAIL_RCPT:
2110-
name = "CURLOPT_MAIL_RCPT";
2111-
break;
2112-
case CURLOPT_RESOLVE:
2113-
name = "CURLOPT_RESOLVE";
2114-
break;
2115-
case CURLOPT_PROXYHEADER:
2116-
name = "CURLOPT_PROXYHEADER";
2117-
break;
2118-
case CURLOPT_CONNECT_TO:
2119-
name = "CURLOPT_CONNECT_TO";
2120-
break;
2121-
}
21222089

21232090
if (Z_TYPE_P(zvalue) != IS_ARRAY) {
2124-
zend_type_error("%s(): The %s option must have an array value", get_active_function_name(), name);
2091+
const struct curl_easyoption *option_info = curl_easy_option_by_id(option);
2092+
zend_type_error("%s(): The CURLOPT_%s option must have an array value", get_active_function_name(), option_info->name);
21252093
return FAILURE;
21262094
}
21272095

@@ -2133,7 +2101,8 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
21332101
if (zend_str_has_nul_byte(val)) {
21342102
curl_slist_free_all(slist);
21352103
zend_tmp_string_release(tmp_val);
2136-
zend_value_error("%s(): cURL option %s must not contain any null bytes", get_active_function_name(), name);
2104+
const struct curl_easyoption *option_info = curl_easy_option_by_id(option);
2105+
zend_value_error("%s(): cURL option CURLOPT_%s must not contain any null bytes", get_active_function_name(), option_info->name);
21372106
return FAILURE;
21382107
}
21392108

ext/curl/sync-constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
const SOURCE_FILE = __DIR__ . '/curl_arginfo.h';
1414

15-
const MIN_SUPPORTED_CURL_VERSION = '7.61.0';
15+
const MIN_SUPPORTED_CURL_VERSION = '7.73.0';
1616

1717
const IGNORED_CURL_CONSTANTS = [
1818
'CURLOPT_PROGRESSDATA',

ext/curl/tests/bug68089.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ try {
1616
?>
1717
Done
1818
--EXPECT--
19-
curl_setopt(): cURL option must not contain any null bytes
19+
curl_setopt(): cURL option CURLOPT_URL must not contain any null bytes
2020
Done

0 commit comments

Comments
 (0)