@@ -1309,6 +1309,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
1309
1309
return ;
1310
1310
1311
1311
std::vector<nghttp2_header> headers (stream->move_headers ());
1312
+ DecrementCurrentSessionMemory (stream->current_headers_length_ );
1313
+ stream->current_headers_length_ = 0 ;
1312
1314
1313
1315
// The headers are passed in above as a queue of nghttp2_header structs.
1314
1316
// The following converts that into a JS array with the structure:
@@ -1942,6 +1944,7 @@ Http2Stream::~Http2Stream() {
1942
1944
if (session_ == nullptr )
1943
1945
return ;
1944
1946
Debug (this , " tearing down stream" );
1947
+ session_->DecrementCurrentSessionMemory (current_headers_length_);
1945
1948
session_->RemoveStream (this );
1946
1949
session_ = nullptr ;
1947
1950
}
@@ -1956,6 +1959,7 @@ std::string Http2Stream::diagnostic_name() const {
1956
1959
void Http2Stream::StartHeaders (nghttp2_headers_category category) {
1957
1960
Debug (this , " starting headers, category: %d" , id_, category);
1958
1961
CHECK (!this ->IsDestroyed ());
1962
+ session_->DecrementCurrentSessionMemory (current_headers_length_);
1959
1963
current_headers_length_ = 0 ;
1960
1964
current_headers_.clear ();
1961
1965
current_headers_category_ = category;
@@ -2225,8 +2229,12 @@ bool Http2Stream::AddHeader(nghttp2_rcbuf* name,
2225
2229
CHECK (!this ->IsDestroyed ());
2226
2230
if (this ->statistics_ .first_header == 0 )
2227
2231
this ->statistics_ .first_header = uv_hrtime ();
2228
- size_t length = nghttp2_rcbuf_get_buf (name).len +
2229
- nghttp2_rcbuf_get_buf (value).len + 32 ;
2232
+ size_t name_len = nghttp2_rcbuf_get_buf (name).len ;
2233
+ if (name_len == 0 && !IsReverted (SECURITY_REVERT_CVE_2019_9516)) {
2234
+ return true ; // Ignore headers with empty names.
2235
+ }
2236
+ size_t value_len = nghttp2_rcbuf_get_buf (value).len ;
2237
+ size_t length = name_len + value_len + 32 ;
2230
2238
// A header can only be added if we have not exceeded the maximum number
2231
2239
// of headers and the session has memory available for it.
2232
2240
if (!session_->IsAvailableSessionMemory (length) ||
@@ -2242,6 +2250,7 @@ bool Http2Stream::AddHeader(nghttp2_rcbuf* name,
2242
2250
nghttp2_rcbuf_incref (name);
2243
2251
nghttp2_rcbuf_incref (value);
2244
2252
current_headers_length_ += length;
2253
+ session_->IncrementCurrentSessionMemory (length);
2245
2254
return true ;
2246
2255
}
2247
2256
0 commit comments