summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-09-25 11:25:02 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-09-25 13:51:18 +0200
commita49555a9e1547a513e2f22d0a2a3ef92cddbec3d (patch)
treed48913df7583698a2dc197b9565f4396e82dd74d
parente74f89d95a1e33181f70f35cd8ccffe5dc0bb98b (diff)
downloadphp-git-a49555a9e1547a513e2f22d0a2a3ef92cddbec3d.tar.gz
Fix #80147: BINARY strings may not be properly zero-terminated
We have to manually ensure that all strings fetched from a data source are zero-terminated. Closes GH-6213.
-rw-r--r--NEWS2
-rw-r--r--ext/odbc/php_odbc.c1
-rw-r--r--ext/odbc/tests/bug80147.phpt27
3 files changed, 30 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 35a928af07..21c054c981 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,8 @@ PHP NEWS
- ODBC:
. Fixed bug #78470 (odbc_specialcolumns() no longer accepts $nullable). (cmb)
+ . Fixed bug #80147 (BINARY strings may not be properly zero-terminated).
+ (cmb)
- OPcache:
. Fixed bug #80083 (Optimizer pass 6 removes variables used for ibm_db2 data
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index c2d1a8f846..a93252f7c4 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -2221,6 +2221,7 @@ PHP_FUNCTION(odbc_result)
if (rc != SQL_SUCCESS_WITH_INFO) {
field_str = zend_string_truncate(field_str, result->values[field_ind].vallen, 0);
}
+ ZSTR_VAL(field_str)[ZSTR_LEN(field_str)] = '\0';
RETURN_NEW_STR(field_str);
break;
diff --git a/ext/odbc/tests/bug80147.phpt b/ext/odbc/tests/bug80147.phpt
new file mode 100644
index 0000000000..26e27c534e
--- /dev/null
+++ b/ext/odbc/tests/bug80147.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #80147 (BINARY strings may not be properly zero-terminated)
+--SKIPIF--
+<?php include 'skipif.inc'; ?>
+--FILE--
+<?php
+include 'config.inc';
+
+$conn = odbc_connect($dsn, $user, $pass);
+
+odbc_exec($conn, "CREATE TABLE bug80147 (id INT, whatever VARBINARY(50))");
+odbc_exec($conn, "INSERT INTO bug80147 VALUES (1, CONVERT(VARBINARY(50), 'whatever'))");
+
+$res = odbc_exec($conn, "SELECT * FROM bug80147");
+odbc_binmode($res, ODBC_BINMODE_RETURN);
+odbc_fetch_row($res);
+var_dump(odbc_result($res, 'whatever'));
+?>
+--CLEAN--
+<?php
+include 'config.inc';
+
+$conn = odbc_connect($dsn, $user, $pass);
+odbc_exec($conn, "DROP TABLE bug80147");
+?>
+--EXPECT--
+string(8) "whatever"