From 743c75849c8aa3ff2336b244bc33ebb57a47f8a3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 25 Sep 2020 11:25:02 +0200 Subject: [PATCH] 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. --- ext/odbc/php_odbc.c | 1 + ext/odbc/tests/bug80147.phpt | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ext/odbc/tests/bug80147.phpt diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index c2d1a8f846f92..a93252f7c450a 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 0000000000000..26e27c534ebac --- /dev/null +++ b/ext/odbc/tests/bug80147.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #80147 (BINARY strings may not be properly zero-terminated) +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +string(8) "whatever"