Skip to content

Commit 5ad1b89

Browse files
committed
Use more specific types instead of int in cURL extension
1 parent 0d013cd commit 5ad1b89

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

ext/curl/curl_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ php_curl *init_curl_handle_into_zval(zval *curl);
140140
void init_curl_handle(php_curl *ch);
141141
void _php_curl_cleanup_handle(php_curl *);
142142
void _php_curl_multi_cleanup_list(void *data);
143-
void _php_curl_verify_handlers(php_curl *ch, int reporterror);
143+
void _php_curl_verify_handlers(php_curl *ch, bool reporterror);
144144
void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source);
145145

146146
static inline php_curl *curl_from_obj(zend_object *obj) {

ext/curl/interface.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static ZEND_ATTRIBUTE_UNUSED unsigned long php_curl_ssl_id(void)
9696
# define php_curl_ret(__ret) RETVAL_FALSE; return;
9797
#endif
9898

99-
static int php_curl_option_str(php_curl *ch, zend_long option, const char *str, const size_t len)
99+
static zend_result php_curl_option_str(php_curl *ch, zend_long option, const char *str, const size_t len)
100100
{
101101
if (strlen(str) != len) {
102102
zend_value_error("%s(): cURL option must not contain any null bytes", get_active_function_name());
@@ -109,7 +109,7 @@ static int php_curl_option_str(php_curl *ch, zend_long option, const char *str,
109109
return error == CURLE_OK ? SUCCESS : FAILURE;
110110
}
111111

112-
static int php_curl_option_url(php_curl *ch, const char *url, const size_t len) /* {{{ */
112+
static zend_result php_curl_option_url(php_curl *ch, const char *url, const size_t len) /* {{{ */
113113
{
114114
/* Disable file:// if open_basedir are used */
115115
if (PG(open_basedir) && *PG(open_basedir)) {
@@ -131,7 +131,7 @@ static int php_curl_option_url(php_curl *ch, const char *url, const size_t len)
131131
}
132132
/* }}} */
133133

134-
void _php_curl_verify_handlers(php_curl *ch, int reporterror) /* {{{ */
134+
void _php_curl_verify_handlers(php_curl *ch, bool reporterror) /* {{{ */
135135
{
136136
php_stream *stream;
137137

@@ -226,7 +226,7 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n);
226226
static zend_function *curl_get_constructor(zend_object *object);
227227
static zend_object *curl_clone_obj(zend_object *object);
228228
php_curl *init_curl_handle_into_zval(zval *curl);
229-
static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields);
229+
static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpostfields);
230230

231231
/* {{{ PHP_INI_BEGIN */
232232
PHP_INI_BEGIN()
@@ -1249,7 +1249,7 @@ static zend_object *curl_clone_obj(zend_object *object) {
12491249

12501250
postfields = &clone_ch->postfields;
12511251
if (Z_TYPE_P(postfields) != IS_UNDEF) {
1252-
if (build_mime_structure_from_hash(clone_ch, postfields) != SUCCESS) {
1252+
if (build_mime_structure_from_hash(clone_ch, postfields) == FAILURE) {
12531253
zend_throw_exception(NULL, "Failed to clone CurlHandle", 0);
12541254
return &clone_ch->std;
12551255
}
@@ -1391,7 +1391,7 @@ static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
13911391
php_error_docref(NULL, E_WARNING, "Could not call the CURLOPT_WRITEFUNCTION");
13921392
length = -1;
13931393
} else if (!Z_ISUNDEF(retval)) {
1394-
_php_curl_verify_handlers(ch, 1);
1394+
_php_curl_verify_handlers(ch, /* reporterror */ true);
13951395
length = zval_get_long(&retval);
13961396
}
13971397

@@ -1413,7 +1413,7 @@ static int curl_fnmatch(void *ctx, const char *pattern, const char *string)
14131413
int rval = CURL_FNMATCHFUNC_FAIL;
14141414
zval argv[3];
14151415
zval retval;
1416-
int error;
1416+
zend_result error;
14171417
zend_fcall_info fci;
14181418

14191419
GC_ADDREF(&ch->std);
@@ -1435,7 +1435,7 @@ static int curl_fnmatch(void *ctx, const char *pattern, const char *string)
14351435
if (error == FAILURE) {
14361436
php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_FNMATCH_FUNCTION");
14371437
} else if (!Z_ISUNDEF(retval)) {
1438-
_php_curl_verify_handlers(ch, 1);
1438+
_php_curl_verify_handlers(ch, /* reporterror */ true);
14391439
rval = zval_get_long(&retval);
14401440
}
14411441
zval_ptr_dtor(&argv[0]);
@@ -1459,7 +1459,7 @@ static size_t curl_progress(void *clientp, double dltotal, double dlnow, double
14591459

14601460
zval argv[5];
14611461
zval retval;
1462-
int error;
1462+
zend_result error;
14631463
zend_fcall_info fci;
14641464

14651465
GC_ADDREF(&ch->std);
@@ -1483,7 +1483,7 @@ static size_t curl_progress(void *clientp, double dltotal, double dlnow, double
14831483
if (error == FAILURE) {
14841484
php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_PROGRESSFUNCTION");
14851485
} else if (!Z_ISUNDEF(retval)) {
1486-
_php_curl_verify_handlers(ch, 1);
1486+
_php_curl_verify_handlers(ch, /* reporterror */ true);
14871487
if (0 != zval_get_long(&retval)) {
14881488
rval = 1;
14891489
}
@@ -1509,7 +1509,7 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
15091509
case PHP_CURL_USER: {
15101510
zval argv[3];
15111511
zval retval;
1512-
int error;
1512+
zend_result error;
15131513
zend_fcall_info fci;
15141514

15151515
GC_ADDREF(&ch->std);
@@ -1537,7 +1537,7 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
15371537
php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_READFUNCTION");
15381538
length = CURL_READFUNC_ABORT;
15391539
} else if (!Z_ISUNDEF(retval)) {
1540-
_php_curl_verify_handlers(ch, 1);
1540+
_php_curl_verify_handlers(ch, /* reporterror */ true);
15411541
if (Z_TYPE(retval) == IS_STRING) {
15421542
length = MIN((int) (size * nmemb), Z_STRLEN(retval));
15431543
memcpy(data, Z_STRVAL(retval), length);
@@ -1577,7 +1577,7 @@ static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx
15771577
case PHP_CURL_USER: {
15781578
zval argv[2];
15791579
zval retval;
1580-
int error;
1580+
zend_result error;
15811581
zend_fcall_info fci;
15821582

15831583
GC_ADDREF(&ch->std);
@@ -1599,7 +1599,7 @@ static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx
15991599
php_error_docref(NULL, E_WARNING, "Could not call the CURLOPT_HEADERFUNCTION");
16001600
length = -1;
16011601
} else if (!Z_ISUNDEF(retval)) {
1602-
_php_curl_verify_handlers(ch, 1);
1602+
_php_curl_verify_handlers(ch, /* reporterror */ true);
16031603
length = zval_get_long(&retval);
16041604
}
16051605
zval_ptr_dtor(&argv[0]);
@@ -1988,7 +1988,7 @@ static void free_cb(void *arg) /* {{{ */
19881988
/* }}} */
19891989
#endif
19901990

1991-
static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields) /* {{{ */
1991+
static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpostfields) /* {{{ */
19921992
{
19931993
HashTable *postfields = Z_ARRVAL_P(zpostfields);
19941994
CURLcode error = CURLE_OK;
@@ -2260,7 +2260,7 @@ PHP_FUNCTION(curl_copy_handle)
22602260

22612261
postfields = &ch->postfields;
22622262
if (Z_TYPE_P(postfields) != IS_UNDEF) {
2263-
if (build_mime_structure_from_hash(dupch, postfields) != SUCCESS) {
2263+
if (build_mime_structure_from_hash(dupch, postfields) == FAILURE) {
22642264
zval_ptr_dtor(return_value);
22652265
php_error_docref(NULL, E_WARNING, "Cannot rebuild mime structure");
22662266
RETURN_FALSE;
@@ -2269,7 +2269,7 @@ PHP_FUNCTION(curl_copy_handle)
22692269
}
22702270
/* }}} */
22712271

2272-
static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool is_array_config) /* {{{ */
2272+
static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool is_array_config) /* {{{ */
22732273
{
22742274
CURLcode error = CURLE_OK;
22752275
zend_long lval;
@@ -2435,12 +2435,12 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
24352435
if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
24362436
(PG(open_basedir) && *PG(open_basedir)) && (lval & CURLPROTO_FILE)) {
24372437
php_error_docref(NULL, E_WARNING, "CURLPROTO_FILE cannot be activated when an open_basedir is set");
2438-
return 1;
2438+
return FAILURE;
24392439
}
24402440
# if defined(ZTS)
24412441
if (option == CURLOPT_DNS_USE_GLOBAL_CACHE && lval) {
24422442
php_error_docref(NULL, E_WARNING, "CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled");
2443-
return 1;
2443+
return FAILURE;
24442444
}
24452445
# endif
24462446
error = curl_easy_setopt(ch->cp, option, lval);
@@ -2533,7 +2533,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
25332533
{
25342534
zend_string *tmp_str;
25352535
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2536-
int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str));
2536+
zend_result ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str));
25372537
zend_tmp_string_release(tmp_str);
25382538
return ret;
25392539
}
@@ -2563,7 +2563,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
25632563
} else {
25642564
zend_string *tmp_str;
25652565
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2566-
int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str));
2566+
zend_result ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str));
25672567
zend_tmp_string_release(tmp_str);
25682568
return ret;
25692569
}
@@ -2583,7 +2583,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
25832583
{
25842584
zend_string *tmp_str;
25852585
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2586-
int ret = php_curl_option_url(ch, ZSTR_VAL(str), ZSTR_LEN(str));
2586+
zend_result ret = php_curl_option_url(ch, ZSTR_VAL(str), ZSTR_LEN(str));
25872587
zend_tmp_string_release(tmp_str);
25882588
return ret;
25892589
}
@@ -2757,7 +2757,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
27572757
zend_tmp_string_release(tmp_val);
27582758
if (!slist) {
27592759
php_error_docref(NULL, E_WARNING, "Could not build curl_slist");
2760-
return 1;
2760+
return FAILURE;
27612761
}
27622762
} ZEND_HASH_FOREACH_END();
27632763

@@ -2881,7 +2881,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
28812881
{
28822882
zend_string *tmp_str;
28832883
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
2884-
int ret;
2884+
zend_result ret;
28852885

28862886
if (ZSTR_LEN(str) && php_check_open_basedir(ZSTR_VAL(str))) {
28872887
zend_tmp_string_release(tmp_str);
@@ -3056,7 +3056,7 @@ PHP_FUNCTION(curl_exec)
30563056

30573057
ch = Z_CURL_P(zid);
30583058

3059-
_php_curl_verify_handlers(ch, 1);
3059+
_php_curl_verify_handlers(ch, /* reporterror */ true);
30603060

30613061
_php_curl_cleanup_handle(ch);
30623062

@@ -3427,7 +3427,7 @@ static void curl_free_obj(zend_object *object)
34273427
return;
34283428
}
34293429

3430-
_php_curl_verify_handlers(ch, 0);
3430+
_php_curl_verify_handlers(ch, /* reporterror */ false);
34313431

34323432
/*
34333433
* Libcurl is doing connection caching. When easy handle is cleaned up,

ext/curl/multi.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ PHP_FUNCTION(curl_multi_add_handle)
8888
mh = Z_CURL_MULTI_P(z_mh);
8989
ch = Z_CURL_P(z_ch);
9090

91-
_php_curl_verify_handlers(ch, 1);
91+
_php_curl_verify_handlers(ch, /* reporterror */ true);
9292

9393
_php_curl_cleanup_handle(ch);
9494

@@ -217,7 +217,7 @@ PHP_FUNCTION(curl_multi_exec)
217217
pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
218218
ch = Z_CURL_P(pz_ch);
219219

220-
_php_curl_verify_handlers(ch, 1);
220+
_php_curl_verify_handlers(ch, /* reporterror */ true);
221221
}
222222
}
223223

@@ -318,7 +318,7 @@ PHP_FUNCTION(curl_multi_close)
318318
for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
319319
pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
320320
php_curl *ch = Z_CURL_P(pz_ch);
321-
_php_curl_verify_handlers(ch, 1);
321+
_php_curl_verify_handlers(ch, /* reporterror */ true);
322322
curl_multi_remove_handle(mh->multi, ch->cp);
323323
}
324324
zend_llist_clean(&mh->easyh);
@@ -374,7 +374,7 @@ static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_hea
374374
zval headers;
375375
zval retval;
376376
char *header;
377-
int error;
377+
zend_result error;
378378
zend_fcall_info fci = empty_fcall_info;
379379

380380
pz_parent_ch = _php_curl_multi_find_easy_handle(mh, parent_ch);
@@ -428,7 +428,8 @@ static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_hea
428428

429429
#endif
430430

431-
static int _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
431+
/* Returns true on failure, false on success */
432+
static bool _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
432433
{
433434
CURLMcode error = CURLM_OK;
434435

@@ -544,7 +545,7 @@ void curl_multi_free_obj(zend_object *object)
544545
pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
545546
if (!(OBJ_FLAGS(Z_OBJ_P(pz_ch)) & IS_OBJ_FREE_CALLED)) {
546547
ch = Z_CURL_P(pz_ch);
547-
_php_curl_verify_handlers(ch, 0);
548+
_php_curl_verify_handlers(ch, /* reporterror */ false);
548549
}
549550
}
550551

ext/curl/share.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ PHP_FUNCTION(curl_share_close)
5353
}
5454
/* }}} */
5555

56-
static int _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
56+
/* Returns true on failure, false on success */
57+
static bool _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
5758
{
5859
CURLSHcode error = CURLSHE_OK;
5960

0 commit comments

Comments
 (0)