Skip to content

Commit f674a33

Browse files
committed
Fix #80592: all floats are the same in ODBC parameters
We must not release the strings until we are done with them. Closes GH-6579.
1 parent 44a311d commit f674a33

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ PHP NEWS
3232
. Fixed bug #77935 (Crash in mysqlnd_fetch_stmt_row_cursor when calling an SP
3333
with a cursor). (Nikita)
3434

35+
- ODBC:
36+
. Fixed bug #80592 (all floats are the same in ODBC parameters). (cmb)
37+
3538
- PDO_Firebird:
3639
. Fixed bug #80521 (Parameters with underscores no longer recognized). (cmb,
3740
Simonov Denis)

ext/odbc/php_odbc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ PHP_FUNCTION(odbc_prepare)
963963
typedef struct odbc_params_t {
964964
SQLLEN vallen;
965965
int fp;
966+
zend_string *zstr;
966967
} odbc_params_t;
967968

968969
static void odbc_release_params(odbc_result *result, odbc_params_t *params) {
@@ -971,6 +972,9 @@ static void odbc_release_params(odbc_result *result, odbc_params_t *params) {
971972
if (params[i].fp != -1) {
972973
close(params[i].fp);
973974
}
975+
if (params[i].zstr) {
976+
zend_string_release(params[i].zstr);
977+
}
974978
}
975979
efree(params);
976980
}
@@ -1004,6 +1008,7 @@ PHP_FUNCTION(odbc_execute)
10041008
params = (odbc_params_t *)safe_emalloc(sizeof(odbc_params_t), result->numparams, 0);
10051009
for(i = 0; i < result->numparams; i++) {
10061010
params[i].fp = -1;
1011+
params[i].zstr = NULL;
10071012
}
10081013

10091014
i = 1;
@@ -1017,6 +1022,7 @@ PHP_FUNCTION(odbc_execute)
10171022

10181023
params[i-1].vallen = ZSTR_LEN(tmpstr);
10191024
params[i-1].fp = -1;
1025+
params[i-1].zstr = tmpstr;
10201026

10211027
if (IS_SQL_BINARY(result->param_info[i-1].sqltype)) {
10221028
ctype = SQL_C_BINARY;
@@ -1030,7 +1036,6 @@ PHP_FUNCTION(odbc_execute)
10301036

10311037
if (ZSTR_LEN(tmpstr) != strlen(ZSTR_VAL(tmpstr))) {
10321038
odbc_release_params(result, params);
1033-
zend_string_release(tmpstr);
10341039
RETURN_FALSE;
10351040
}
10361041
filename = estrndup(&ZSTR_VAL(tmpstr)[1], ZSTR_LEN(tmpstr) - 2);
@@ -1040,14 +1045,12 @@ PHP_FUNCTION(odbc_execute)
10401045
if (php_check_open_basedir(filename)) {
10411046
efree(filename);
10421047
odbc_release_params(result, params);
1043-
zend_string_release(tmpstr);
10441048
RETURN_FALSE;
10451049
}
10461050

10471051
if ((params[i-1].fp = open(filename,O_RDONLY)) == -1) {
10481052
php_error_docref(NULL, E_WARNING,"Can't open file %s", filename);
10491053
odbc_release_params(result, params);
1050-
zend_string_release(tmpstr);
10511054
efree(filename);
10521055
RETURN_FALSE;
10531056
}
@@ -1076,10 +1079,8 @@ PHP_FUNCTION(odbc_execute)
10761079
if (rc == SQL_ERROR) {
10771080
odbc_sql_error(result->conn_ptr, result->stmt, "SQLBindParameter");
10781081
odbc_release_params(result, params);
1079-
zend_string_release(tmpstr);
10801082
RETURN_FALSE;
10811083
}
1082-
zend_string_release(tmpstr);
10831084
if (++i > result->numparams) break;
10841085
} ZEND_HASH_FOREACH_END();
10851086
}

ext/odbc/tests/bug80592.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #80592 (all floats are the same in ODBC parameters)
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
include 'config.inc';
8+
9+
$conn = odbc_connect($dsn, $user, $pass);
10+
odbc_exec($conn,"CREATE TABLE bug80592 (f1 float not null, f2 float not null, f3 float not null)");
11+
$stmt = odbc_prepare($conn, "INSERT INTO bug80592 (f1, f2, f3) values (?, ?, ?)");
12+
odbc_execute($stmt, [1.0, 2.0, 3.0]);
13+
$res = odbc_exec($conn, "SELECT f1, f2, f3 from bug80592");
14+
var_dump(odbc_fetch_array($res));
15+
?>
16+
--CLEAN--
17+
<?php
18+
include 'config.inc';
19+
20+
$conn = odbc_connect($dsn, $user, $pass);
21+
odbc_exec($conn, "DROP TABLE bug80592");
22+
?>
23+
--EXPECT--
24+
array(3) {
25+
["f1"]=>
26+
string(3) "1.0"
27+
["f2"]=>
28+
string(3) "2.0"
29+
["f3"]=>
30+
string(3) "3.0"
31+
}

0 commit comments

Comments
 (0)