mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
ircd::json: Limit IOV size and take stringify buffer off-stack.
This commit is contained in:
parent
96818c9a46
commit
373a791158
2 changed files with 20 additions and 4 deletions
|
@ -38,9 +38,6 @@ namespace ircd::json
|
||||||
struct ircd::json::iov
|
struct ircd::json::iov
|
||||||
:ircd::iov<ircd::json::member>
|
:ircd::iov<ircd::json::member>
|
||||||
{
|
{
|
||||||
IRCD_EXCEPTION(json::error, error);
|
|
||||||
IRCD_EXCEPTION(error, exists);
|
|
||||||
|
|
||||||
struct push;
|
struct push;
|
||||||
struct add;
|
struct add;
|
||||||
struct add_if;
|
struct add_if;
|
||||||
|
@ -49,6 +46,12 @@ struct ircd::json::iov
|
||||||
struct defaults;
|
struct defaults;
|
||||||
struct defaults_if;
|
struct defaults_if;
|
||||||
|
|
||||||
|
IRCD_EXCEPTION(json::error, error);
|
||||||
|
IRCD_EXCEPTION(error, exists);
|
||||||
|
IRCD_EXCEPTION(error, oversize);
|
||||||
|
|
||||||
|
static const size_t MAX_SIZE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool has(const string_view &key) const;
|
bool has(const string_view &key) const;
|
||||||
const value &at(const string_view &key) const;
|
const value &at(const string_view &key) const;
|
||||||
|
|
15
ircd/json.cc
15
ircd/json.cc
|
@ -368,6 +368,12 @@ ircd::json::input<it>::throws_exceeded()
|
||||||
// iov.h
|
// iov.h
|
||||||
//
|
//
|
||||||
|
|
||||||
|
decltype(ircd::json::iov::MAX_SIZE)
|
||||||
|
ircd::json::iov::MAX_SIZE
|
||||||
|
{
|
||||||
|
1024
|
||||||
|
};
|
||||||
|
|
||||||
std::ostream &
|
std::ostream &
|
||||||
ircd::json::operator<<(std::ostream &s, const iov &iov)
|
ircd::json::operator<<(std::ostream &s, const iov &iov)
|
||||||
{
|
{
|
||||||
|
@ -379,7 +385,14 @@ ircd::string_view
|
||||||
ircd::json::stringify(mutable_buffer &buf,
|
ircd::json::stringify(mutable_buffer &buf,
|
||||||
const iov &iov)
|
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, []
|
std::transform(std::begin(iov), std::end(iov), m, []
|
||||||
(const member &m)
|
(const member &m)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue