mirror of
https://github.com/boostorg/beast.git
synced 2025-08-03 06:44:39 +02:00
Handle bad_alloc in parser
This commit is contained in:
@@ -5,6 +5,7 @@ Version 66:
|
||||
* Make consuming_buffers smaller
|
||||
* Fix costly potential value-init in parser
|
||||
* Fix unused parameter warning
|
||||
* Handle bad_alloc in parser
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@@ -80,6 +80,13 @@ enum class error
|
||||
*/
|
||||
buffer_overflow,
|
||||
|
||||
/** A memory allocation failed.
|
||||
|
||||
When basic_fields throws std::bad_alloc, it is
|
||||
converted into this error by @ref parser.
|
||||
*/
|
||||
bad_alloc,
|
||||
|
||||
//
|
||||
// (parser errors)
|
||||
//
|
||||
|
@@ -44,6 +44,7 @@ public:
|
||||
case error::unexpected_body: return "unexpected body";
|
||||
case error::need_buffer: return "need buffer";
|
||||
case error::buffer_overflow: return "buffer overflow";
|
||||
case error::bad_alloc: return "bad alloc";
|
||||
case error::bad_line_ending: return "bad line ending";
|
||||
case error::bad_method: return "bad method";
|
||||
case error::bad_path: return "bad path";
|
||||
|
@@ -198,12 +198,19 @@ private:
|
||||
on_request(verb method, string_view method_str,
|
||||
string_view target, int version, error_code& ec)
|
||||
{
|
||||
ec.assign(0, ec.category());
|
||||
m_.target(target);
|
||||
if(method != verb::unknown)
|
||||
m_.method(method);
|
||||
else
|
||||
m_.method_string(method_str);
|
||||
try
|
||||
{
|
||||
m_.target(target);
|
||||
if(method != verb::unknown)
|
||||
m_.method(method);
|
||||
else
|
||||
m_.method_string(method_str);
|
||||
ec.assign(0, ec.category());
|
||||
}
|
||||
catch(std::bad_alloc const&)
|
||||
{
|
||||
ec = error::bad_alloc;
|
||||
}
|
||||
m_.version = version;
|
||||
}
|
||||
|
||||
@@ -212,18 +219,32 @@ private:
|
||||
string_view reason,
|
||||
int version, error_code& ec)
|
||||
{
|
||||
ec.assign(0, ec.category());
|
||||
m_.result(code);
|
||||
m_.version = version;
|
||||
m_.reason(reason);
|
||||
try
|
||||
{
|
||||
m_.reason(reason);
|
||||
ec.assign(0, ec.category());
|
||||
}
|
||||
catch(std::bad_alloc const&)
|
||||
{
|
||||
ec = error::bad_alloc;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
on_field(field name, string_view name_string,
|
||||
string_view value, error_code& ec)
|
||||
{
|
||||
ec.assign(0, ec.category());
|
||||
m_.insert(name, name_string, value);
|
||||
try
|
||||
{
|
||||
m_.insert(name, name_string, value);
|
||||
ec.assign(0, ec.category());
|
||||
}
|
||||
catch(std::bad_alloc const&)
|
||||
{
|
||||
ec = error::bad_alloc;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -42,6 +42,7 @@ public:
|
||||
check("beast.http", error::unexpected_body);
|
||||
check("beast.http", error::need_buffer);
|
||||
check("beast.http", error::buffer_overflow);
|
||||
check("beast.http", error::bad_alloc);
|
||||
|
||||
check("beast.http", error::bad_line_ending);
|
||||
check("beast.http", error::bad_method);
|
||||
|
Reference in New Issue
Block a user