Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/core/packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ class Packet
// read
Packet(size_t prefix_length)
{
// Bug 9 hardening: prefix_length comes from m_node->get_prefix().size()
// in Socket::init(). If m_node has been destroyed mid-handshake (UAF
// from rapid disconnect-reconnect — Bug-3-family), the vector's size
// field reads garbage and resize() throws std::length_error
// ("vector::_M_default_append") which kills the process. All known
// protocols have a 4-byte magic prefix; cap at 16 to reject UAF
// garbage cleanly and let the connection fail without crashing.
constexpr size_t MAX_PREFIX_LENGTH = 16;
if (prefix_length > MAX_PREFIX_LENGTH) {
throw std::ios_base::failure("Packet prefix_length exceeds cap (likely UAF on m_node)");
}
prefix.resize(prefix_length);
}

Expand Down
Loading