Skip to content

Commit 354f2d9

Browse files
jasnellevanlucas
authored andcommitted
http2: fixup http2stream cleanup and other nits
This fixes CVE-2018-7161. PR-URL: https://github.com/nodejs-private/node-private/pull/123 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent c5a2748 commit 354f2d9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/node_http2.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ Http2Session::~Http2Session() {
548548
ClearWrap(object());
549549
persistent().Reset();
550550
CHECK(persistent().IsEmpty());
551+
for (const auto& iter : streams_)
552+
iter.second->session_ = nullptr;
551553
Unconsume();
552554
DEBUG_HTTP2SESSION(this, "freeing nghttp2 session");
553555
nghttp2_session_del(session_);
@@ -693,6 +695,8 @@ inline void Http2Session::AddStream(Http2Stream* stream) {
693695

694696

695697
inline void Http2Session::RemoveStream(Http2Stream* stream) {
698+
if (streams_.empty() || stream == nullptr)
699+
return; // Nothing to remove, item was never added?
696700
streams_.erase(stream->id());
697701
DecrementCurrentSessionMemory(stream->self_size());
698702
}
@@ -1778,8 +1782,8 @@ Http2Stream::Http2Stream(
17781782

17791783

17801784
Http2Stream::~Http2Stream() {
1781-
DEBUG_HTTP2STREAM(this, "tearing down stream");
17821785
if (session_ != nullptr) {
1786+
DEBUG_HTTP2STREAM(this, "tearing down stream");
17831787
session_->RemoveStream(this);
17841788
session_ = nullptr;
17851789
}

src/node_http2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ class Http2Stream : public AsyncWrap,
723723
Statistics statistics_ = {};
724724

725725
private:
726-
Http2Session* session_; // The Parent HTTP/2 Session
727-
int32_t id_; // The Stream Identifier
726+
Http2Session* session_ = nullptr; // The Parent HTTP/2 Session
727+
int32_t id_ = 0; // The Stream Identifier
728728
int32_t code_ = NGHTTP2_NO_ERROR; // The RST_STREAM code (if any)
729729
int flags_ = NGHTTP2_STREAM_FLAG_NONE; // Internal state flags
730730

0 commit comments

Comments
 (0)