[Boost-bugs] [Boost C++ Libraries] #7928: boost::interprocess::shared_memory_object creation cause infinite loop

Subject: [Boost-bugs] [Boost C++ Libraries] #7928: boost::interprocess::shared_memory_object creation cause infinite loop
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-01-25 18:24:18


#7928: boost::interprocess::shared_memory_object creation cause infinite loop
------------------------------+---------------------------------------------
 Reporter: lsopko@… | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: interprocess
  Version: Boost 1.52.0 | Severity: Showstopper
 Keywords: |
------------------------------+---------------------------------------------
 Call of '''boost::interprocess::shared_memory_object''' creation cause
 infinite loop in case there is:
 boost::interprocess::shared_memory_object shm (
 boost::interprocess::open_or_create,
 "some-name",
 boost::interprocess::read_write,
 256);
 I dig inside of code and it happen in file:

 '''boost/interprocess/shared_memory_object.hpp'''

  this function :

 inline '''bool''' '''shared_memory_object::priv_open_or_create'''
    (ipcdetail::create_enum_t type,
     const char *filename,
     mode_t mode, const permissions &perm)
 {
 .....

 in switch/case:
 ....
 case '''ipcdetail::DoOpenOrCreate''':
       {
          oflag |= O_CREAT;
          //We need a loop to change permissions correctly using fchmod,
 since
          //with "O_CREAT only" shm_open we don't know if we've created or
 opened the file.
          while(1){
             m_handle = shm_open(m_filename.c_str(), oflag, unix_perm);
             if(m_handle >= 0){
                ::fchmod(m_handle, unix_perm);
                break;
             }
             else if(errno == EEXIST){
                if((m_handle = shm_open(m_filename.c_str(), oflag,
 unix_perm)) >= 0 || errno != ENOENT){
                   break;
                }
             }
          }
       }

 ... as you can see there is a while and this while will remain infinite in
 case of any other errno then: "'''EEXIST'''"

 ... there are 9 different errors possible in case of shm_open() call,
 so they should be handled, in my case it was EACCES what brick my testing.

 I'm testing it on '''1.50''' but saw '''1.52''' have the same code .....

 Reagards

 Ladislav Sopko
 lsopko_at_[hidden]

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7928>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC