beast: buffer overflow handling for string_body and mutable_body

Beast/v70

Was looking at test coverage to find untested parts to increase coverage. So i discovered this:

            try
            {
                body_.resize(len + n);
            }
            catch(std::length_error const&)
            {
                ec = error::buffer_overflow;
                return;
            }
            ec.assign(0, ec.category());

There you catch std::length_error only. What about the exceptions thrown by corresponding Allocator? e.g. std::bad_alloc

http://en.cppreference.com/w/cpp/string/basic_string/resize

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 26 (26 by maintainers)

Commits related to this issue

Most upvoted comments

Is “Fix buffer overflow handling for string_body” as commit message okay?

By the way, these are the kinds of bugs we like, easy to fix and doesn’t change any public interfaces. As long as there is no major design problem with interfaces, then we’re in good shape - things like this can be cleaned up over time (not saying we shouldn’t fix it now but this is not as severe as an interface design flaw).

I would suggest catching std::exception and always mapping to error::buffer_overflow.