@@ -1318,6 +1318,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
1318
1318
return ;
1319
1319
1320
1320
std::vector<nghttp2_header> headers (stream->move_headers ());
1321
+ DecrementCurrentSessionMemory (stream->current_headers_length_ );
1322
+ stream->current_headers_length_ = 0 ;
1321
1323
1322
1324
Local<String> name_str;
1323
1325
Local<String> value_str;
@@ -1975,6 +1977,7 @@ Http2Stream::~Http2Stream() {
1975
1977
if (session_ == nullptr )
1976
1978
return ;
1977
1979
Debug (this , " tearing down stream" );
1980
+ session_->DecrementCurrentSessionMemory (current_headers_length_);
1978
1981
session_->RemoveStream (this );
1979
1982
session_ = nullptr ;
1980
1983
}
@@ -1989,6 +1992,7 @@ std::string Http2Stream::diagnostic_name() const {
1989
1992
void Http2Stream::StartHeaders (nghttp2_headers_category category) {
1990
1993
Debug (this , " starting headers, category: %d" , id_, category);
1991
1994
CHECK (!this ->IsDestroyed ());
1995
+ session_->DecrementCurrentSessionMemory (current_headers_length_);
1992
1996
current_headers_length_ = 0 ;
1993
1997
current_headers_.clear ();
1994
1998
current_headers_category_ = category;
@@ -2260,8 +2264,12 @@ bool Http2Stream::AddHeader(nghttp2_rcbuf* name,
2260
2264
CHECK (!this ->IsDestroyed ());
2261
2265
if (this ->statistics_ .first_header == 0 )
2262
2266
this ->statistics_ .first_header = uv_hrtime ();
2263
- size_t length = nghttp2_rcbuf_get_buf (name).len +
2264
- nghttp2_rcbuf_get_buf (value).len + 32 ;
2267
+ size_t name_len = nghttp2_rcbuf_get_buf (name).len ;
2268
+ if (name_len == 0 && !IsReverted (SECURITY_REVERT_CVE_2019_9516)) {
2269
+ return true ; // Ignore headers with empty names.
2270
+ }
2271
+ size_t value_len = nghttp2_rcbuf_get_buf (value).len ;
2272
+ size_t length = name_len + value_len + 32 ;
2265
2273
// A header can only be added if we have not exceeded the maximum number
2266
2274
// of headers and the session has memory available for it.
2267
2275
if (!session_->IsAvailableSessionMemory (length) ||
@@ -2277,6 +2285,7 @@ bool Http2Stream::AddHeader(nghttp2_rcbuf* name,
2277
2285
nghttp2_rcbuf_incref (name);
2278
2286
nghttp2_rcbuf_incref (value);
2279
2287
current_headers_length_ += length;
2288
+ session_->IncrementCurrentSessionMemory (length);
2280
2289
return true ;
2281
2290
}
2282
2291
0 commit comments