Skip to content

Commit 8681402

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/115 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent 9ba8ed1 commit 8681402

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/node_http2.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ Http2Session::Http2Session(Environment* env,
499499
Http2Session::~Http2Session() {
500500
CHECK_EQ(flags_ & SESSION_STATE_HAS_SCOPE, 0);
501501
Debug(this, "freeing nghttp2 session");
502+
for (const auto& iter : streams_)
503+
iter.second->session_ = nullptr;
502504
nghttp2_session_del(session_);
503505
}
504506

@@ -651,6 +653,8 @@ inline void Http2Session::AddStream(Http2Stream* stream) {
651653

652654

653655
inline void Http2Session::RemoveStream(Http2Stream* stream) {
656+
if (streams_.empty() || stream == nullptr)
657+
return; // Nothing to remove, item was never added?
654658
streams_.erase(stream->id());
655659
DecrementCurrentSessionMemory(stream->self_size());
656660
}

src/node_http2.h

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

653653
private:
654-
Http2Session* session_; // The Parent HTTP/2 Session
655-
int32_t id_; // The Stream Identifier
654+
Http2Session* session_ = nullptr; // The Parent HTTP/2 Session
655+
int32_t id_ = 0; // The Stream Identifier
656656
int32_t code_ = NGHTTP2_NO_ERROR; // The RST_STREAM code (if any)
657657
int flags_ = NGHTTP2_STREAM_FLAG_NONE; // Internal state flags
658658

0 commit comments

Comments
 (0)