[Boost-bugs] [Boost C++ Libraries] #8925: libs/log/src/event.cpp: might not retireve last error correctly

Subject: [Boost-bugs] [Boost C++ Libraries] #8925: libs/log/src/event.cpp: might not retireve last error correctly
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-07-25 06:00:03


#8925: libs/log/src/event.cpp: might not retireve last error correctly
--------------------------------------------+---------------------
 Reporter: Jeffrey Walton <noloader@…> | Owner: andysem
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: log
  Version: Boost 1.54.0 | Severity: Problem
 Keywords: GetLastError Win32 API failure |
--------------------------------------------+---------------------
 The following code may not retrieve the last error correctly.

 if (WaitForSingleObject(m_event, INFINITE) != 0)
 {
     BOOST_THROW_EXCEPTION(system::system_error(
       GetLastError(), system::system_category(), "Failed to block on
 Windows event"));
 }

 If the compile evaluates the args in BOOST_THROW_EXCEPTION from left to
 right, system::system_error could call on a Win32 API that blows away the
 error. Conversely, if the args are evaluated right to left, then
 system::system_category() or the "Failed to block on Windows event" string
 could cause last error to get blown away.

 My apologies for the write-up. After looking at a number of uses of
 WaitForSingleObject in Boost, this is one of the few (fewer than 5) that
 is correct.

 Perhaps something like below would be easier to audit for correctness:

 if (WaitForSingleObject(m_event, INFINITE) != 0)
 {
     DWORD dwError = GetLastError();
     BOOST_THROW_EXCEPTION(system::system_error(
       dwError, system::system_category(), "Failed to block on Windows
 event"));
 }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8925>
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:13 UTC