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

Bug #3420 XML Container lacks shared lock
Submitted: 2005-02-09 22:49 UTC
From: ylf at xung dot org Assigned: quipo
Status: Closed Package: Translation2
PHP Version: 4.3.4 OS: Linux Debian
Roadmaps: (Not assigned)    
Subscription  


 [2005-02-09 22:49 UTC] ylf at xung dot org
Description: ------------ Hi, Translation2 version : 2.0.0beta6 AFAIK, flock() provides _advisory_ locks. In Translation2/Admin/Container/xml.php, line 340, you state : @flock($f, LOCK_EX); fwrite ($f, $xml); @flock($f, LOCK_UN); fclose ($f); Sidenote: @flock ($f,LOCK_UN) is useless, fclose() unlocks the file. An "exclusive" (LOCK_EX) advisory lock does not forbid other processes to read from the file. These processes need to explicitly acquire a shared lock. From the flock Linux manpage : "flock(2) places advisory locks only; given suitable permissions on a file, a process is free to ignore the use of flock(2) and perform I/O on the file." In our case it means that you correctly acquire an exclusive lock when writing to the xml file, but you forget to acquire a shared lock when reading. Consequence : the lock is ignored by reading processes. The call to flock($f,LOCK_EX) should protect the file from getting corrupted, but there are chances to read junk from it. You should turn, in Container/xml.php, line 137 : $unserializer = &new XML_Unserializer (array('keyAttribute' => $keyAttr)); if (PEAR::isError($status = $unserializer->unserialize($this->_filename, true))) { return $status; } into : if (!$fp = @fopen ($this->_filename, 'r')) { return new PEAR_Error ("Can\'t read from the XML source : {$this->_filename}"); } @flock ($fp, LOCK_SH); $unserializer = &new XML_Unserializer (array('keyAttribute' => $keyAttr)); if (PEAR::isError($status = $unserializer->unserialize($this->_filename, true))) { fclose ($fp); return $status; } fclose($fp); Cheers

Comments

 [2005-02-10 08:09 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!