Skip to content

Fix bug #67704: CURLOPT_POSTFIELDS modify the type of param base php-5.5 #927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2524,10 +2524,22 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
zend_hash_get_current_data(ph, (void **) &current) == SUCCESS;
zend_hash_move_forward(ph)
) {
SEPARATE_ZVAL(current);
convert_to_string_ex(current);
zval tmp_current;
zval *tmp_current_ptr = NULL;

if (Z_TYPE_PP(current) != IS_STRING) {
tmp_current = **current;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use ZVAL_COPY_VALUE macro here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laruence in 5.5 that doesn't work if the left operand is &tmp_current; I think that was only changed in master.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@datibbaw okey.. :<

zval_copy_ctor(&tmp_current);
convert_to_string(&tmp_current);
tmp_current_ptr = &tmp_current;
current = &tmp_current_ptr;
}

slist = curl_slist_append(slist, Z_STRVAL_PP(current));

if (tmp_current_ptr) {
zval_dtor(tmp_current_ptr);
}
if (!slist) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not build curl_slist");
return 1;
Expand Down Expand Up @@ -2587,7 +2599,9 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
uint string_key_len;
ulong num_key;
int numeric_key;

zval tmp_current;
zval *tmp_current_ptr = NULL;

zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);

/* Pretend we have a string_key here */
Expand Down Expand Up @@ -2636,9 +2650,14 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
}
continue;
}

SEPARATE_ZVAL(current);
convert_to_string_ex(current);

if (Z_TYPE_PP(current) != IS_STRING) {
tmp_current = **current;
zval_copy_ctor(&tmp_current);
convert_to_string(&tmp_current);
tmp_current_ptr = &tmp_current;
current = &tmp_current_ptr;
}

postval = Z_STRVAL_PP(current);

Expand Down Expand Up @@ -2686,6 +2705,9 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
if (numeric_key) {
efree(string_key);
}
if (tmp_current_ptr) {
zval_dtor(tmp_current_ptr);
}
}

SAVE_CURL_ERROR(ch, error);
Expand Down
65 changes: 65 additions & 0 deletions ext/curl/tests/bug67704.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
--TEST--
Bug #67704 (CURLOPT_POSTFIELDS modify the type of param)
--SKIPIF--
<?php
if (!extension_loaded("curl")) {
exit("skip curl extension not loaded");
}
?>
--FILE--
<?php
$ch = curl_init();
$post_data = array('a' => 1, 'b' => '2');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
var_dump($post_data['a']);
curl_close($ch);

$ch = curl_init();
$one = 1;
$post_data = array('a' => $one, 'b' => '2');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
var_dump($post_data['a']);
curl_close($ch);

$ch = curl_init();
$one_with_ref = 1;
$post_data = array('a' => &$one_with_ref, 'b' => '2');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
var_dump($post_data['a']);
curl_close($ch);

$ch = curl_init();
$post_data = array('a' => true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
var_dump($post_data['a']);
curl_close($ch);

$ch = curl_init();
$header = array('a' => 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
var_dump($header['a']);
curl_close($ch);

$ch = curl_init();
$one = 1;
$header = array('a' => $one);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
var_dump($header['a']);
curl_close($ch);

$ch = curl_init();
$two_with_ref = 2;
$header = array('a' => &$two_with_ref);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
var_dump($header['a']);
curl_close($ch);

?>
--EXPECTF--
int(1)
int(1)
int(1)
bool(true)
int(1)
int(1)
int(2)