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] quipo
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. -- many thanks for the patch!