Skip to content

Commit 3d14880

Browse files
committed
Merge branch 'PHP-7.4' into master
* PHP-7.4: Fix #80147: BINARY strings may not be properly zero-terminated
2 parents 439878c + 1086e4e commit 3d14880

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

ext/odbc/php_odbc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,7 @@ PHP_FUNCTION(odbc_result)
18701870
if (rc != SQL_SUCCESS_WITH_INFO) {
18711871
field_str = zend_string_truncate(field_str, result->values[field_ind].vallen, 0);
18721872
}
1873+
ZSTR_VAL(field_str)[ZSTR_LEN(field_str)] = '\0';
18731874
RETURN_NEW_STR(field_str);
18741875
break;
18751876

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)