0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-28 06:48:20 +02:00

ircd::json: Limit IOV size and take stringify buffer off-stack.

This commit is contained in:
Jason Volk 2018-03-17 11:52:28 -07:00
parent 96818c9a46
commit 373a791158
2 changed files with 20 additions and 4 deletions

View file

@ -38,9 +38,6 @@ namespace ircd::json
struct ircd::json::iov
:ircd::iov<ircd::json::member>
{
IRCD_EXCEPTION(json::error, error);
IRCD_EXCEPTION(error, exists);
struct push;
struct add;
struct add_if;
@ -49,6 +46,12 @@ struct ircd::json::iov
struct defaults;
struct defaults_if;
IRCD_EXCEPTION(json::error, error);
IRCD_EXCEPTION(error, exists);
IRCD_EXCEPTION(error, oversize);
static const size_t MAX_SIZE;
public:
bool has(const string_view &key) const;
const value &at(const string_view &key) const;

View file

@ -368,6 +368,12 @@ ircd::json::input<it>::throws_exceeded()
// iov.h
//
decltype(ircd::json::iov::MAX_SIZE)
ircd::json::iov::MAX_SIZE
{
1024
};
std::ostream &
ircd::json::operator<<(std::ostream &s, const iov &iov)
{
@ -379,7 +385,14 @@ ircd::string_view
ircd::json::stringify(mutable_buffer &buf,
const iov &iov)
{
const member *m[iov.size()];
const ctx::critical_assertion ca;
thread_local const member *m[iov.MAX_SIZE];
if(unlikely(size_t(iov.size()) > iov.MAX_SIZE))
throw iov::oversize
{
"IOV has %zd members but maximum is %zu", iov.size(), iov.MAX_SIZE
};
std::transform(std::begin(iov), std::end(iov), m, []
(const member &m)
{