@@ -1328,6 +1328,8 @@ inline void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
1328
1328
return ;
1329
1329
1330
1330
std::vector<nghttp2_header> headers (stream->move_headers ());
1331
+ DecrementCurrentSessionMemory (stream->current_headers_length_ );
1332
+ stream->current_headers_length_ = 0 ;
1331
1333
1332
1334
Local<String> name_str;
1333
1335
Local<String> value_str;
@@ -2021,6 +2023,7 @@ Http2Stream::~Http2Stream() {
2021
2023
if (session_ == nullptr )
2022
2024
return ;
2023
2025
DEBUG_HTTP2STREAM (this , " tearing down stream" );
2026
+ session_->DecrementCurrentSessionMemory (current_headers_length_);
2024
2027
session_->RemoveStream (this );
2025
2028
session_ = nullptr ;
2026
2029
@@ -2032,6 +2035,7 @@ Http2Stream::~Http2Stream() {
2032
2035
void Http2Stream::StartHeaders (nghttp2_headers_category category) {
2033
2036
DEBUG_HTTP2STREAM2 (this , " starting headers, category: %d" , id_, category);
2034
2037
CHECK (!this ->IsDestroyed ());
2038
+ session_->DecrementCurrentSessionMemory (current_headers_length_);
2035
2039
current_headers_length_ = 0 ;
2036
2040
current_headers_.clear ();
2037
2041
current_headers_category_ = category;
@@ -2323,10 +2327,6 @@ inline int Http2Stream::DoWrite(WriteWrap* req_wrap,
2323
2327
return 0 ;
2324
2328
}
2325
2329
2326
- inline size_t GetBufferLength (nghttp2_rcbuf* buf) {
2327
- return nghttp2_rcbuf_get_buf (buf).len ;
2328
- }
2329
-
2330
2330
// Ads a header to the Http2Stream. Note that the header name and value are
2331
2331
// provided using a buffer structure provided by nghttp2 that allows us to
2332
2332
// avoid unnecessary memcpy's. Those buffers are ref counted. The ref count
@@ -2338,7 +2338,12 @@ inline bool Http2Stream::AddHeader(nghttp2_rcbuf* name,
2338
2338
CHECK (!this ->IsDestroyed ());
2339
2339
if (this ->statistics_ .first_header == 0 )
2340
2340
this ->statistics_ .first_header = uv_hrtime ();
2341
- size_t length = GetBufferLength (name) + GetBufferLength (value) + 32 ;
2341
+ size_t name_len = nghttp2_rcbuf_get_buf (name).len ;
2342
+ if (name_len == 0 && !IsReverted (SECURITY_REVERT_CVE_2019_9516)) {
2343
+ return true ; // Ignore headers with empty names.
2344
+ }
2345
+ size_t value_len = nghttp2_rcbuf_get_buf (value).len ;
2346
+ size_t length = name_len + value_len + 32 ;
2342
2347
// A header can only be added if we have not exceeded the maximum number
2343
2348
// of headers and the session has memory available for it.
2344
2349
if (!session_->IsAvailableSessionMemory (length) ||
@@ -2354,6 +2359,7 @@ inline bool Http2Stream::AddHeader(nghttp2_rcbuf* name,
2354
2359
nghttp2_rcbuf_incref (name);
2355
2360
nghttp2_rcbuf_incref (value);
2356
2361
current_headers_length_ += length;
2362
+ session_->IncrementCurrentSessionMemory (length);
2357
2363
return true ;
2358
2364
}
2359
2365
0 commit comments