diff --git a/src/quic/node_quic_socket-inl.h b/src/quic/node_quic_socket-inl.h index 3e9adab6f263c2..8156fd04ad7bf5 100644 --- a/src/quic/node_quic_socket-inl.h +++ b/src/quic/node_quic_socket-inl.h @@ -18,6 +18,7 @@ namespace quic { std::unique_ptr QuicPacket::Create( const char* diagnostic_label, size_t len) { + CHECK_LE(len, MAX_PKTLEN); return std::make_unique(diagnostic_label, len); } @@ -27,8 +28,8 @@ std::unique_ptr QuicPacket::Copy( } void QuicPacket::set_length(size_t len) { - CHECK_LE(len, data_.size()); - data_.resize(len); + CHECK_LE(len, MAX_PKTLEN); + len_ = len; } int QuicEndpoint::Send( diff --git a/src/quic/node_quic_socket.cc b/src/quic/node_quic_socket.cc index 839c33f5bf42db..28ca2a52336a1c 100644 --- a/src/quic/node_quic_socket.cc +++ b/src/quic/node_quic_socket.cc @@ -83,14 +83,15 @@ bool IsShortHeader( } // namespace QuicPacket::QuicPacket(const char* diagnostic_label, size_t len) : - data_(len), + data_{0}, + len_(len), diagnostic_label_(diagnostic_label) { - CHECK_LE(len, NGTCP2_MAX_PKT_SIZE); + CHECK_LE(len, MAX_PKTLEN); } QuicPacket::QuicPacket(const QuicPacket& other) : - QuicPacket(other.diagnostic_label_, other.data_.size()) { - memcpy(data_.data(), other.data_.data(), other.data_.size()); + QuicPacket(other.diagnostic_label_, other.len_) { + memcpy(&data_, &other.data_, other.len_); } const char* QuicPacket::diagnostic_label() const { @@ -98,9 +99,7 @@ const char* QuicPacket::diagnostic_label() const { diagnostic_label_ : "unspecified"; } -void QuicPacket::MemoryInfo(MemoryTracker* tracker) const { - tracker->TrackField("data", data_); -} +void QuicPacket::MemoryInfo(MemoryTracker* tracker) const {} QuicSocketListener::~QuicSocketListener() { if (socket_) diff --git a/src/quic/node_quic_socket.h b/src/quic/node_quic_socket.h index 01f6e276563abb..badad5aed1e82c 100644 --- a/src/quic/node_quic_socket.h +++ b/src/quic/node_quic_socket.h @@ -112,6 +112,13 @@ class JSQuicSocketListener : public QuicSocketListener { void OnDestroy() override; }; +// This is just a formality as the QUIC spec normatively +// defines that the ipv4 max pktlen is always going to be +// larger than the ipv6 max pktlen, but in the off chance +// ever changes (which is unlikely) we check here. +constexpr size_t MAX_PKTLEN = + std::max(NGTCP2_MAX_PKTLEN_IPV4, NGTCP2_MAX_PKTLEN_IPV6); + // A serialized QuicPacket to be sent by a QuicSocket instance. class QuicPacket : public MemoryRetainer { public: @@ -141,7 +148,7 @@ class QuicPacket : public MemoryRetainer { // QuicPacket instance will be freed. static inline std::unique_ptr Create( const char* diagnostic_label = nullptr, - size_t len = NGTCP2_MAX_PKTLEN_IPV4); + size_t len = MAX_PKTLEN); // Copy the data of the QuicPacket to a new one. Currently, // this is only used when retransmitting close connection @@ -151,11 +158,11 @@ class QuicPacket : public MemoryRetainer { QuicPacket(const char* diagnostic_label, size_t len); QuicPacket(const QuicPacket& other); - uint8_t* data() { return data_.data(); } - size_t length() const { return data_.size(); } + uint8_t* data() { return data_; } + size_t length() const { return len_; } uv_buf_t buf() const { return uv_buf_init( - const_cast(reinterpret_cast(data_.data())), + const_cast(reinterpret_cast(&data_)), length()); } inline void set_length(size_t len); @@ -166,7 +173,8 @@ class QuicPacket : public MemoryRetainer { SET_SELF_SIZE(QuicPacket); private: - std::vector data_; + uint8_t data_[MAX_PKTLEN]; + size_t len_ = MAX_PKTLEN; const char* diagnostic_label_ = nullptr; };