Opened 9 years ago

Closed 9 years ago

#8925 closed Bugs (fixed)

libs/log/src/event.cpp: might not retireve last error correctly

Reported by: Jeffrey Walton <noloader@…> Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.54.0 Severity: Problem
Keywords: GetLastError Win32 API failure Cc:

Description

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"));

}

Change History (1)

comment:1 by Andrey Semashev, 9 years ago

Resolution: fixed
Status: newclosed

(In [85198]) GetLastError and errno usage made more reliable. Fixes #8925.

Note: See TracTickets for help on using tickets.