|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-05-10 02:18 UTC] morozov at tut dot by
Description:
------------
If a value of a (VAR)?CHAR FOR BIT DATA field contains NULL-bytes, the value gets truncated after the first one.
Test script:
---------------
$stmt = db2_prepare($conn, 'CREATE TABLE TEST_TABLE(VAL VARCHAR(16) FOR BIT DATA NOT NULL)');
db2_execute($stmt);
$stmt = db2_prepare($conn, 'INSERT INTO TEST_TABLE VALUES(X\'410042\')');
db2_execute($stmt);
$stmt = db2_prepare($conn, 'SELECT VAL, LENGTH(VAL) LEN FROM test_table');
db2_execute($stmt);
$row = db2_fetch_assoc($stmt);
var_dump($row);
Expected result:
----------------
array(2) {
'VAL' =>
string(3) "A.B"
'LEN' =>
int(3)
}
Actual result:
--------------
array(2) {
'VAL' =>
string(1) "A"
'LEN' =>
int(3)
}
Patchesfix-76322 (last revision 2021-08-06 18:11 UTC by cmb@php.net)fix_for_defect (last revision 2018-08-10 08:39 UTC by vnkbabu@php.net) Pull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 03:00:01 2025 UTC |
Combined with other issues, it can lead to a security hole like: function register_user($email) { if (substr($email, -12) !== '@company.com') { die('Employees only'); } $id = create_user($email); // later $email = get_user_email($id); send_activation($email); } register_user("evil@hacker.org\0@company.com");Hi, This is expected behavior, we are storing A"NULL" B in our database, while printing we are only printing A since after that we are encountering "NULL" hence not able to print B. From output we can check length retrieved from DB is 3. Actual result: -------------- array(2) { 'VAL' => string(1) "A" 'LEN' => int(3) in HEX 00 corrosponds to "NULL" if you want to give "." then please use "2e".Hi, What I meant was, when X'410042' is stored while printing PHP is truncating it as it encountered null, data is properly stored in application buffer after fetch. var_dump() is not able to print beyond "NULL" but buffer holds complete data. pasting below gdb output. (gdb) p str $15 = 0x7ffff6801118 "A" (gdb) p/x *(str+1) $16 = 0x0 (gdb) p/x *(str+2) $17 = 0x42 and output also shows retrieved data is 3 length string. array(2) { 'VAL' => string(1) "A" 'LEN' => int(3) <<<<<<<<<<<<<<< 3 byte string. } Please let me know if I am misinterpreting something. Thanks,