From: glideraerobatics at hotmail dot com
Operating system: Linux
PHP version: 5.0.3
PHP Bug Type: Unknown/Other Function
Bug description: shmop_read() doesn't stop reading at NULL byte.
Description:
------------
Either shmop_read() doesn't stop reading when it encouters a NULL byte, or
shmop_write() doesn't write a NULL byte at the end of a string in the
shared memory segment.
Reproduce code:
---------------
<?php
error_reporting(E_ALL | E_STRICT);
$key = make_key('TEST');
$mode = 'c';
$perms = 0644;
$size = 80;
$shm_id = shmop_open($key, $mode, $perms, $size);
if (!$shm_id) {
throw new Exception(sprintf('shmop_open(%x, "%s", 0%o, %u) failed.',
$key, $mode, $perms, $size));
}
print 'Opened shm size: ' . shmop_size($shm_id) . "\n";
// Write long string.
$value = 'This is a kind of very long string.';
$result = shmop_write($shm_id, $value, 0);
printf("shmop_write(%x, '%s', 0) returned: %d\n", $shm_id, $value,
$result);
// Read string back in.
$result = shmop_read($shm_id, 0, shmop_size($shm_id));
printf("shmop_read(%x, 0, %d) returned: '%s'\n", $shm_id,
shmop_size($shm_id), $result);
// Write short string.
$value = 'This is short.';
$result = shmop_write($shm_id, $value, 0);
printf("shmop_write(%x, '%s', 0) returned: %d\n", $shm_id, $value,
$result);
// Read string back in.
$result = shmop_read($shm_id, 0, shmop_size($shm_id));
printf("shmop_read(%x, 0, %d) returned: '%s'\n", $shm_id,
shmop_size($shm_id), $result);
function make_key($value) {
return ord(substr($value,0,1)) | (ord(substr($value,1,1))<<8) |
(ord(substr($value,2,1))<<16) | (ord(substr($value,3,1)) << 24); //intel
endian
}
?>
Expected result:
----------------
I expected the 1st shmop_read() call to return:
'This is a kind of very long string.'
....which it does, but I expected the 2nd shmop_read() call to return:
'This is short.'
...which it doesn't.
Actual result:
--------------
The 1st shmop_read() call returns:
'This is a kind of very long string.'
The 2nd shmop_read() call returns:
'This is short. of very long string.'
...which includes the trailing part of the first and longer string written
with shmop_write().
--
Edit bug report at http://bugs.php.net/?id=31445&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31445&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=31445&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=31445&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31445&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31445&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31445&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31445&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31445&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31445&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31445&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=31445&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=31445&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31445&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31445&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31445&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31445&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31445&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31445&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31445&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31445&r=mysqlcfg