Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.0RC1

Bug #11971 Minor fix for SystemV shared memory
Submitted: 2007-09-04 04:48 UTC
From: atrerra Assigned:
Status: Open Package: System_SharedMemory (version CVS)
PHP Version: 5.1.3 OS: linux
Roadmaps: (Not assigned)    
Subscription  


 [2007-09-04 04:48 UTC] atrerra (Mark Thomson)
Description: ------------ The function _s2i() in Systemv.php is meant to return an integer for use as a unique key in shm_* calls. However it returns an array and not an integer. The calling function does not throw an error however. Test script: --------------- Simply create 2 or more shared memory variables then simply save+retrieve them. Due to the bug, all variables will have the same key "Array" and therefore the same value upon get() -ing them. Expected result: ---------------- Here is the very simple fix (sorry can't roll a patch at the moment) // in systemV.php, the function: //------------ function _s2i($name) { return unpack('N', str_pad($name, 4, "\0", STR_PAD_LEFT)); } //Should be: //---------- function _s2i($name) { return array_shift(unpack('N', str_pad($name, 4, "\0", STR_PAD_LEFT))); } // Since unpack returns an array not an integer as needed

Comments

 [2007-09-10 00:08 UTC] atrerra (Mark Thomson)
On further reflection the pack() method for generating an key only considers the first four characters of $name in generating the key. i.e. unpack('N', 'var_a') = 1986097759 unpack('N', 'var_b') = 1986097759 Why not use crc32($name) or md5($name) to generate the key? Of course there is the remote possibility of collisions this way, but at least it frees up the possibility of using > 4 character length variable names. Cheers.