Skip to content

Commit 1086e4e

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #80147: BINARY strings may not be properly zero-terminated
2 parents 54cbee5 + a49555a commit 1086e4e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ PHP NEWS
1616

1717
- ODBC:
1818
. Fixed bug #78470 (odbc_specialcolumns() no longer accepts $nullable). (cmb)
19+
. Fixed bug #80147 (BINARY strings may not be properly zero-terminated).
20+
(cmb)
1921

2022
- OPcache:
2123
. Fixed bug #80083 (Optimizer pass 6 removes variables used for ibm_db2 data

ext/odbc/php_odbc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,7 @@ PHP_FUNCTION(odbc_result)
22202220
if (rc != SQL_SUCCESS_WITH_INFO) {
22212221
field_str = zend_string_truncate(field_str, result->values[field_ind].vallen, 0);
22222222
}
2223+
ZSTR_VAL(field_str)[ZSTR_LEN(field_str)] = '\0';
22232224
RETURN_NEW_STR(field_str);
22242225
break;
22252226

ext/odbc/tests/bug80147.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #80147 (BINARY strings may not be properly zero-terminated)
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
include 'config.inc';
8+
9+
$conn = odbc_connect($dsn, $user, $pass);
10+
11+
odbc_exec($conn, "CREATE TABLE bug80147 (id INT, whatever VARBINARY(50))");
12+
odbc_exec($conn, "INSERT INTO bug80147 VALUES (1, CONVERT(VARBINARY(50), 'whatever'))");
13+
14+
$res = odbc_exec($conn, "SELECT * FROM bug80147");
15+
odbc_binmode($res, ODBC_BINMODE_RETURN);
16+
odbc_fetch_row($res);
17+
var_dump(odbc_result($res, 'whatever'));
18+
?>
19+
--CLEAN--
20+
<?php
21+
include 'config.inc';
22+
23+
$conn = odbc_connect($dsn, $user, $pass);
24+
odbc_exec($conn, "DROP TABLE bug80147");
25+
?>
26+
--EXPECT--
27+
string(8) "whatever"

0 commit comments

Comments
 (0)