Skip to content

Commit ba7de8f

Browse files
committed
Workaround truncation bug
1 parent f3f334a commit ba7de8f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ibm_db2.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5878,13 +5878,20 @@ PHP_FUNCTION(db2_result)
58785878
}
58795879
memset(out_ptr, 0, in_length * 2);
58805880
rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_CHAR, out_ptr, in_length, &out_length);
5881+
//fprintf(stderr, " ** strlen %d in_length %d out_length %d\n", strlen(out_ptr), in_length, out_length);
58815882
if (out_length > (in_length * 2)) {
58825883
php_error_docref(NULL, E_WARNING, "SQLGetData returned more data than what was provided; possible memory corruption");
58835884
/* should abort here */
58845885
}
5885-
if (out_length > in_length) {
5886-
/* yup. let's just chop it off and hope it doesn't get too worse */
5887-
((char*)out_ptr)[in_length + 1] = '\0';
5886+
/*
5887+
* CB 20210325: Truncate unconditionally; CLI may not null
5888+
* terminate properly if CCSID is properly set (XXX)
5889+
*
5890+
* Size was already expanded by one, so reference the last byte
5891+
* and make it terminated. Thanks, I hate it!
5892+
*/
5893+
if (in_length > 1) {
5894+
((char*)out_ptr)[in_length - 1] = '\0';
58885895
}
58895896
#else
58905897
out_ptr = (SQLPOINTER)ecalloc(1, in_length);

0 commit comments

Comments
 (0)