Skip to content

Commit 8f50036

Browse files
authored
Merge pull request #61 from php/fix-column-name
Fix garbage in column names on IBM i
2 parents 8cf053a + 155d36c commit 8f50036

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ibm_db2.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,13 @@ static int _php_db2_get_result_set_info(stmt_handle *stmt_res)
19711971
return -1;
19721972
}
19731973
} else {
1974-
stmt_res->column_info[i].name = (SQLCHAR *)estrdup(tmp_name);
1974+
/*
1975+
* CB20241114: In some cases on i (i.e. QP2SHELL w/ CCSID 65535),
1976+
* SQL/CLI might not add a null terminator, and garbage can appear
1977+
* at the end of column names. However, name_length is still
1978+
* correct, so we truncate with that when copying the name.
1979+
*/
1980+
stmt_res->column_info[i].name = (SQLCHAR *)estrndup(tmp_name, name_length);
19751981
}
19761982
switch (stmt_res->column_info[i].type) {
19771983
/* BIGINT 9223372036854775807 (2^63-1) string convert */

0 commit comments

Comments
 (0)