Skip to content

Commit 828159f

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/122 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent f0af3b0 commit 828159f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/node_http2.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ Http2Session::Http2Session(Environment* env,
500500
Http2Session::~Http2Session() {
501501
CHECK_EQ(flags_ & SESSION_STATE_HAS_SCOPE, 0);
502502
DEBUG_HTTP2SESSION(this, "freeing nghttp2 session");
503+
for (const auto& iter : streams_)
504+
iter.second->session_ = nullptr;
503505
nghttp2_session_del(session_);
504506
}
505507

@@ -643,6 +645,8 @@ inline void Http2Session::AddStream(Http2Stream* stream) {
643645

644646

645647
inline void Http2Session::RemoveStream(Http2Stream* stream) {
648+
if (streams_.empty() || stream == nullptr)
649+
return; // Nothing to remove, item was never added?
646650
streams_.erase(stream->id());
647651
DecrementCurrentSessionMemory(stream->self_size());
648652
}
@@ -1697,8 +1701,8 @@ Http2Stream::Http2Stream(
16971701

16981702

16991703
Http2Stream::~Http2Stream() {
1700-
DEBUG_HTTP2STREAM(this, "tearing down stream");
17011704
if (session_ != nullptr) {
1705+
DEBUG_HTTP2STREAM(this, "tearing down stream");
17021706
session_->RemoveStream(this);
17031707
session_ = nullptr;
17041708
}

src/node_http2.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ class Http2Stream : public AsyncWrap,
721721
Statistics statistics_ = {};
722722

723723
private:
724-
Http2Session* session_; // The Parent HTTP/2 Session
725-
int32_t id_; // The Stream Identifier
724+
Http2Session* session_ = nullptr; // The Parent HTTP/2 Session
725+
int32_t id_ = 0; // The Stream Identifier
726726
int32_t code_ = NGHTTP2_NO_ERROR; // The RST_STREAM code (if any)
727727
int flags_ = NGHTTP2_STREAM_FLAG_NONE; // Internal state flags
728728

0 commit comments

Comments
 (0)