@@ -6171,6 +6171,7 @@ static void _php_db2_bind_fetch_helper(INTERNAL_FUNCTION_PARAMETERS, int op)
6171
6171
unsigned char * out_ptr ;
6172
6172
int i5trim = 0 ;
6173
6173
int i5char ;
6174
+ size_t string_length ;
6174
6175
if (zend_parse_parameters (argc , "r|l" , & stmt , & row_number ) == FAILURE ) {
6175
6176
return ;
6176
6177
}
@@ -6287,9 +6288,20 @@ static void _php_db2_bind_fetch_helper(INTERNAL_FUNCTION_PARAMETERS, int op)
6287
6288
case SQL_DECIMAL :
6288
6289
case SQL_NUMERIC :
6289
6290
case SQL_DECFLOAT :
6291
+ /* CB20251003: Sometimes SQL/CLI (at least on IBM i) may
6292
+ * return junk at the end of a buffer. If that's the case,
6293
+ * we should trust out_length. However, it seems we do want
6294
+ * to truncate at the first nul character like strlen does,
6295
+ * (see tests/test_6572_SQLStringsContNULLChar.phpt), so
6296
+ * pick the lower number between the two. Alternatively,
6297
+ * maybe we could consider changing the behaviour around
6298
+ * nul characters? It would make sense for binaries...
6299
+ */
6300
+ string_length = strlen ((char * )row_data -> str_val );
6301
+ string_length = out_length < string_length ? out_length : string_length ;
6290
6302
#ifdef PASE /* i5/OS trim spaces */
6291
6303
if (stmt_res -> s_i5_conn_parent -> c_i5_char_trim > 0 ) {
6292
- i5trim = out_length ;
6304
+ i5trim = string_length ;
6293
6305
for (; i5trim >= 0 ; i5trim -- ) {
6294
6306
i5char = (char )(((char * )row_data -> str_val )[i5trim ]);
6295
6307
if (i5char == 0x00 || i5char == 0x20 ) {
@@ -6316,11 +6328,11 @@ static void _php_db2_bind_fetch_helper(INTERNAL_FUNCTION_PARAMETERS, int op)
6316
6328
#endif /* PASE */
6317
6329
if ( op & DB2_FETCH_ASSOC ) {
6318
6330
add_assoc_stringl (return_value , (char * )stmt_res -> column_info [i ].name ,
6319
- (char * )row_data -> str_val , out_length );
6331
+ (char * )row_data -> str_val , string_length );
6320
6332
}
6321
6333
if ( op & DB2_FETCH_INDEX ) {
6322
6334
add_index_stringl (return_value , i , (char * )row_data -> str_val ,
6323
- out_length );
6335
+ string_length );
6324
6336
}
6325
6337
break ;
6326
6338
case SQL_BOOLEAN :
0 commit comments