0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 02:02:38 +01:00

ircd:Ⓜ️:dbs: Add explicit truncations to limit specific key elements.

This commit is contained in:
Jason Volk 2020-04-06 10:56:03 -07:00
parent dcd50f3427
commit 1bdc87c55e
5 changed files with 12 additions and 8 deletions

View file

@ -247,23 +247,27 @@ ircd::m::dbs::event_state_key(const mutable_buffer &out_,
return {}; return {};
mutable_buffer out{out_}; mutable_buffer out{out_};
consume(out, copy(out, state_key)); consume(out, copy(out, trunc(state_key, event::STATE_KEY_MAX_SIZE)));
if(!type) if(!type)
return {data(out_), data(out)}; return {data(out_), data(out)};
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, type)); consume(out, copy(out, trunc(type, event::TYPE_MAX_SIZE)));
if(!room_id) if(!room_id)
return {data(out_), data(out)}; return {data(out_), data(out)};
assert(m::valid(m::id::ROOM, room_id)); assert(m::valid(m::id::ROOM, room_id));
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, room_id)); consume(out, copy(out, room_id));
if(depth < 0) if(depth < 0)
return {data(out_), data(out)}; return {data(out_), data(out)};
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, byte_view<string_view>(depth))); consume(out, copy(out, byte_view<string_view>(depth)));
if(!event_idx) if(!event_idx)
return {data(out_), data(out)}; return {data(out_), data(out)};

View file

@ -184,7 +184,7 @@ ircd::m::dbs::event_type_key(const mutable_buffer &out_,
assert(size(out_) >= EVENT_TYPE_KEY_MAX_SIZE); assert(size(out_) >= EVENT_TYPE_KEY_MAX_SIZE);
mutable_buffer out{out_}; mutable_buffer out{out_};
consume(out, copy(out, type)); consume(out, copy(out, trunc(type, event::TYPE_MAX_SIZE)));
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, byte_view<string_view>(event_idx))); consume(out, copy(out, byte_view<string_view>(event_idx)));
return { data(out_), data(out) }; return { data(out_), data(out) };

View file

@ -202,13 +202,13 @@ ircd::m::dbs::room_state_key(const mutable_buffer &out_,
if(likely(defined(type))) if(likely(defined(type)))
{ {
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, type)); consume(out, copy(out, trunc(type, event::TYPE_MAX_SIZE)));
} }
if(defined(state_key)) if(defined(state_key))
{ {
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, state_key)); consume(out, copy(out, trunc(state_key, event::STATE_KEY_MAX_SIZE)));
} }
return { data(out_), data(out) }; return { data(out_), data(out) };

View file

@ -326,9 +326,9 @@ ircd::m::dbs::room_state_space_key(const mutable_buffer &out_,
mutable_buffer out{out_}; mutable_buffer out{out_};
consume(out, copy(out, room_id)); consume(out, copy(out, room_id));
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, type)); consume(out, copy(out, trunc(type, event::TYPE_MAX_SIZE)));
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, state_key)); consume(out, copy(out, trunc(state_key, event::STATE_KEY_MAX_SIZE)));
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, byte_view<string_view>(depth))); consume(out, copy(out, byte_view<string_view>(depth)));
consume(out, copy(out, byte_view<string_view>(event_idx))); consume(out, copy(out, byte_view<string_view>(event_idx)));

View file

@ -306,7 +306,7 @@ ircd::m::dbs::room_type_key(const mutable_buffer &out_,
return { data(out_), data(out) }; return { data(out_), data(out) };
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, type)); consume(out, copy(out, trunc(type, event::TYPE_MAX_SIZE)));
consume(out, copy(out, "\0"_sv)); consume(out, copy(out, "\0"_sv));
consume(out, copy(out, byte_view<string_view>(depth))); consume(out, copy(out, byte_view<string_view>(depth)));
consume(out, copy(out, byte_view<string_view>(event_idx))); consume(out, copy(out, byte_view<string_view>(event_idx)));