Bug #15527 Updated: shmop_write(): never writes the null char

From: Date: Tue, 12 Feb 2002 20:07:33 +0000
Subject: Bug #15527 Updated: shmop_write(): never writes the null char
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205@lists.php.net to get a copy of this message
ID: 15527 Updated by: iliaa@php.net Reported By: wboring@qualys.com -Status: Open +Status: Closed Bug Type: Feature/Change Request Operating System: mandrake linux PHP Version: 4.1.1 New Comment: This bug has been fixed in CVS. This particular "feature" already exists in the CVS version of php. You may want to grab it and try it with your source. Previous Comments: ------------------------------------------------------------------------ [2002-02-12 14:46:54] wboring@qualys.com I have a simple script that I'm trying to write/read to shared memory w/ the shmop_* functions. The problem is that it ALWAYS gives me php warnings when reading the value from shared memory. Doing some digging in the code it seems that shmop_write always copies a string to shared memory, but it NEVER null terminates it. This ALWAYS causes shmop_read to report php warnings of Warning: String is not zero-terminated (5„̏***@) (source: zend_execute_API.c:274) in Unknown on line 0 I can't turn warnings off, just to avoid this issue. I need warnings on for debugging of the rest of my site. MY question is, shouldn't shmop_write() always memcopy the stringlen + the NULL character, so when u do a read, this doesn't happen? I know, then u always have to add 1 to the shmop_read(), but isn't that normal to assume u'd want the strlen + 1 for the null char? Here is my script <?php function xmp_var_dump( $var ) { echo "<xmp>\n"; var_dump( $var ); echo "</xmp>\n"; } $key = 0x0ff; $semid = sem_get ( $key, 1, 0666 ); if ( !sem_acquire( $semid ) ) { echo "Can't acquire semaphore<BR>"; exit; } $size = 100; $shmid = shmop_open( $key, 'c', 0, 0 ); //shmop_delete($shmid); //shmop_close($shmid); //exit; if ( $shmid == '' ) { // Get register size: // Create shared memory block $shmid = shmop_open( $key, 'c', 0666, $size ); xmp_var_Dump( $shmid ); if ( $shmid == '' ) { echo "mem.mem: Can't create shared memory"; } else { // Set Header Info: xmp_var_dump( "writing test"); shmop_write( $shmid, 5, 0 ); } } else { $var = shmop_read( $shmid, 0, 1); xmp_var_dump( $var ); } shmop_close($shmid); if( !sem_release( $semid ) ) { echo "find: Can't release semaphore"; exit(); } ?> Warning: shmopen: can't get the block in /home/waboring/devel/current/php/fo/shmem/example3.php on line 22 int(2) string(12) "writing test" Warning: shwrite: write (5), len = 1 in /home/waboring/devel/current/php/fo/shmem/example3.php on line 38 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=15527&edit=1

« previous php.bugs (#205) next »