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