Skip to content

Commit ff24cc8

Browse files
committed
Merge branch 'PHP-8.6'
2 parents d306eb2 + e2d40b5 commit ff24cc8

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

‎ext/odbc/php_odbc.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,21 +952,19 @@ PHP_FUNCTION(odbc_prepare)
952952
}
953953
result->conn_ptr = conn;
954954
result->fetched = 0;
955+
odbc_insert_new_result(conn, return_value);
955956

956957
result->param_info = (odbc_param_info *) safe_emalloc(sizeof(odbc_param_info), result->numparams, 0);
957958
for (i=0;i<result->numparams;i++) {
958959
rc = SQLDescribeParam(result->stmt, (SQLUSMALLINT)(i+1), &result->param_info[i].sqltype, &result->param_info[i].precision,
959960
&result->param_info[i].scale, &result->param_info[i].nullable);
960961
if (rc == SQL_ERROR) {
961962
odbc_sql_error(result->conn_ptr, result->stmt, "SQLDescribeParameter");
962-
SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
963-
efree(result->param_info);
963+
odbc_result_free(result);
964964
zval_ptr_dtor(return_value);
965965
RETURN_FALSE;
966966
}
967967
}
968-
969-
odbc_insert_new_result(conn, return_value);
970968
}
971969
/* }}} */
972970

‎ext/odbc/tests/gh25036.phpt‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
GH-25036 (odbc_prepare() double free when SQLDescribeParam() fails)
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
14+
$live = odbc_exec($conn, 'SELECT 1 AS a');
15+
16+
var_dump(odbc_prepare($conn, 'SELECT ? FROM gh25036_missing'));
17+
var_dump(odbc_prepare($conn, 'SELECT ?, ? FROM gh25036_missing'));
18+
19+
var_dump(odbc_fetch_array($live));
20+
21+
odbc_close($conn);
22+
23+
try {
24+
odbc_fetch_row($live);
25+
} catch (Error $e) {
26+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
27+
}
28+
?>
29+
--EXPECTF--
30+
Warning: odbc_prepare(): SQL error: %s, SQL state %s in SQLDescribeParameter in %s on line %d
31+
bool(false)
32+
33+
Warning: odbc_prepare(): SQL error: %s, SQL state %s in SQLDescribeParameter in %s on line %d
34+
bool(false)
35+
array(1) {
36+
["a"]=>
37+
string(1) "1"
38+
}
39+
Error: ODBC result has already been closed

0 commit comments

Comments
 (0)