Skip to content

Commit 46f74e3

Browse files
committed
Add a test and declare the local vars locally
1 parent c58f254 commit 46f74e3

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

ext/curl/interface.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,10 +2007,6 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
20072007
HashTable *postfields;
20082008
struct HttpPost *first = NULL;
20092009
struct HttpPost *last = NULL;
2010-
char *postval;
2011-
char *string_key = NULL;
2012-
ulong num_key;
2013-
uint string_key_len;
20142010

20152011
postfields = HASH_OF(*zvalue);
20162012
if (!postfields) {
@@ -2023,11 +2019,16 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
20232019
zend_hash_get_current_data(postfields, (void **) &current) == SUCCESS;
20242020
zend_hash_move_forward(postfields)
20252021
) {
2022+
char *postval;
2023+
char *string_key = NULL;
2024+
uint string_key_len;
2025+
ulong num_key;
20262026

20272027
SEPARATE_ZVAL(current);
20282028
convert_to_string_ex(current);
20292029

20302030
zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);
2031+
20312032
/* Pretend we have a string_key here */
20322033
if(!string_key) {
20332034
spprintf(&string_key, 0, "%ld", num_key);

ext/curl/tests/bug55767.phpt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
Test curl_opt() function with POST params from array with a numeric key
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("curl")) exit("skip curl extension not loaded");
6+
if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined");
7+
?>
8+
--FILE--
9+
<?php
10+
/* Prototype : bool curl_setopt(resource ch, int option, mixed value)
11+
* Description: Set an option for a cURL transfer
12+
* Source code: ext/curl/interface.c
13+
* Alias to functions:
14+
*/
15+
16+
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
17+
18+
// start testing
19+
echo '*** Testing curl sending through GET an POST ***' . "\n";
20+
21+
$url = "{$host}/get.php?test=getpost&get_param=Hello%20World";
22+
$ch = curl_init();
23+
24+
ob_start(); // start output buffering
25+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
26+
curl_setopt($ch, CURLOPT_POST, 1);
27+
curl_setopt($ch, CURLOPT_POSTFIELDS, array('Hello'=>'World','Foo'=>'Bar',100=>'John Doe'));
28+
curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
29+
30+
$curl_content = curl_exec($ch);
31+
curl_close($ch);
32+
33+
var_dump( $curl_content );
34+
?>
35+
===DONE===
36+
--EXPECTF--
37+
*** Testing curl sending through GET an POST ***
38+
string(203) "array(2) {
39+
["test"]=>
40+
string(7) "getpost"
41+
["get_param"]=>
42+
string(11) "Hello World"
43+
}
44+
array(3) {
45+
["Hello"]=>
46+
string(5) "World"
47+
["Foo"]=>
48+
string(3) "Bar"
49+
[100]=>
50+
string(8) "John Doe"
51+
}
52+
"
53+
===DONE===

0 commit comments

Comments
 (0)