Opened 9 years ago

Closed 9 years ago

#9734 closed Bugs (fixed)

Wrong check of mmap() return value in coroutine stack allocator

Reported by: Tianlong Wu <rockuw@…> Owned by: olli
Milestone: To Be Determined Component: coroutine
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

In boost source /libs/coroutine/detail/standard_stack_allocator_posix.cpp:120, it has the following snippet:

    void * limit =
# if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
    ::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
# else
    ::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
# endif
    ::close( fd);
    if ( ! limit) throw std::bad_alloc();

It assumes that mmap() returns 0 on fail. However when mmap() fails, the return value is NOT 0, but (void*)-1 instead. This wrong check will bypass the throw and let the error pass down, leading to confusing error message seen by the user.

Change History (1)

comment:1 by olli, 9 years ago

Resolution: fixed
Status: newclosed

test against MAP_FAILED added, thx

Note: See TracTickets for help on using tickets.