Modify

Opened 4 years ago

Closed 4 years ago

#8337 closed Bugs (fixed)

The internal representation of "std::string(this->code()->message())" escapes, but is destroyed when it exits scope.

Reported by: Richard <legalize@…> Owned by: viboes
Milestone: Boost 1.54.0 Component: thread
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc:

Description (last modified by viboes)

Coverity static analysis reported the following problem:

class BOOST_SYMBOL_VISIBLE future_error
     : public std::logic_error
 {
     system::error_code ec_;
 public:
     future_error(system::error_code ec)
     : logic_error(ec.message()),
       ec_(ec)
     {
     }
 
     const system::error_code& code() const BOOST_NOEXCEPT
     {
       return ec_;
     }
     const char* what() const BOOST_THREAD_NOEXCEPT_OR_THROW
     {
 CID 10932 (#2 of 2): Wrapper object use after free (WRAPPER_ESCAPE)1. escape: The internal representation of "std::string(this->code()->message())" escapes, but is destroyed when it exits scope. 
      return code().message().c_str();
     }
 };

Attachments (0)

Change History (5)

comment:1 Changed 4 years ago by viboes

Description: modified (diff)
Owner: changed from Anthony Williams to viboes
Status: newassigned

Could you clarify what is the bug?

comment:2 Changed 4 years ago by Steven Watanabe

boost::system::error_code::message returns a temporary string, which is destroyed when the function returns. The pointer returned by what() is dangling.

comment:3 in reply to:  2 Changed 4 years ago by viboes

Replying to steven_watanabe:

boost::system::error_code::message returns a temporary string, which is destroyed when the function returns. The pointer returned by what() is dangling.

Oh I see. Please could you try just removing the overriding of the what() function?

comment:4 Changed 4 years ago by viboes

Milestone: To Be DeterminedBoost 1.54.0

Committed revision [83649].

comment:5 Changed 4 years ago by viboes

Resolution: fixed
Status: assignedclosed

(In [83660]) Thread: merge from trunk 1.54. Fix #8027,#8323,#8337.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.