Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(http2): check content-length, fix sending RST #53160

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
80fb23f
Check content-length before calling stream_close_callback with error …
Sep 15, 2020
4301a9c
fix(http2): check content-length, fix sending RST
szmarczak May 26, 2024
89a9e5f
fix a test
szmarczak May 26, 2024
d38490a
[skip ci] fix: lint
szmarczak May 26, 2024
e466e73
[skip ci] fix 1 flaky test, 3 more to go
szmarczak May 26, 2024
8647a30
more bug fixes
szmarczak May 26, 2024
2aa3f47
[skip ci] fix a test
szmarczak May 26, 2024
1aedf45
more bug fixes
szmarczak May 26, 2024
cbfd565
fix two tests
szmarczak May 27, 2024
33bdef1
fix goaway bugs
szmarczak May 27, 2024
bbca7d5
fix last test? ill check linux in a sec
szmarczak May 27, 2024
cfeb03c
fix a bug
szmarczak May 28, 2024
2610edb
format cpp
szmarczak May 28, 2024
582284e
fix tests
szmarczak May 29, 2024
5da3bfc
NGHTTP2_CONNECT_ERROR
szmarczak May 29, 2024
26de5ee
test econnreset
szmarczak May 29, 2024
f455077
[skip ci] hascrypto
szmarczak May 29, 2024
9ee21a3
bug fixes
szmarczak May 29, 2024
4f07cc1
fix
szmarczak May 29, 2024
5b74a82
fix errors
szmarczak May 29, 2024
1573a7d
more verbose error checks
szmarczak May 29, 2024
f5f00df
refactor _destroy
szmarczak May 29, 2024
6c1b042
less diff
szmarczak May 29, 2024
9a9774c
fix dropped rsts and goaways
szmarczak May 30, 2024
c4e3be5
[skip ci] fix missing return
szmarczak May 30, 2024
fd3a193
[skip ci] fix that return
szmarczak May 30, 2024
8f1502f
throw on frame error
szmarczak May 30, 2024
0f74296
fix a test
szmarczak May 30, 2024
80f6dd7
fix frame error
szmarczak May 30, 2024
a7d26ec
fix frame errors
szmarczak May 30, 2024
73c2849
send rst on frame error if server
szmarczak May 30, 2024
1755f39
fix that again
szmarczak May 30, 2024
eafd0cc
fix that again
szmarczak May 30, 2024
9581880
Check if session_call_on_frame_received frees the stream in session_a…
szmarczak Oct 4, 2024
217fc63
patch
szmarczak Oct 4, 2024
a990ac8
Allow RST_STREAM before GOAWAY
szmarczak Oct 4, 2024
d15855f
fixup
szmarczak Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/http2/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function main({ n, nheaders }) {
} else {
bench.end(n);
server.close();
client.destroy();
client.close();
}
});
}
Expand Down
13 changes: 10 additions & 3 deletions deps/nghttp2/lib/nghttp2_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,11 @@ int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id,

DEBUGF("stream: stream(%p)=%d close\n", stream, stream->stream_id);

if (error_code == NGHTTP2_NO_ERROR &&
nghttp2_http_on_remote_end_stream(stream) == -1) {
error_code = NGHTTP2_PROTOCOL_ERROR;
}

/* We call on_stream_close_callback even if stream->state is
NGHTTP2_STREAM_INITIAL. This will happen while sending request
HEADERS, a local endpoint receives RST_STREAM for that stream. It
Expand Down Expand Up @@ -2516,9 +2521,6 @@ static int session_prep_frame(nghttp2_session *session,
return 0;
}
case NGHTTP2_RST_STREAM:
if (session_is_closing(session)) {
return NGHTTP2_ERR_SESSION_CLOSING;
}
nghttp2_frame_pack_rst_stream(&session->aob.framebufs, &frame->rst_stream);
return 0;
case NGHTTP2_SETTINGS: {
Expand Down Expand Up @@ -4181,6 +4183,11 @@ static int session_after_header_block_received(nghttp2_session *session) {
return 0;
}

/* on_frame might free the stream */
if (!nghttp2_session_get_stream(session, frame->hd.stream_id)) {
return 0;
}

return session_end_stream_headers_received(session, frame, stream);
}

Expand Down
29 changes: 29 additions & 0 deletions deps/nghttp2/patches/0000-content-length.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 92c120c0ba2ed5806960f8ec9a338fefc17b0427 Mon Sep 17 00:00:00 2001
From: Gil Pedersen <[email protected]>
Date: Tue, 15 Sep 2020 12:36:34 +0000
Subject: [PATCH] Check content-length before calling stream_close_callback
with error code 0

---
deps/nghttp2/lib/nghttp2_session.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/deps/nghttp2/lib/nghttp2_session.c b/deps/nghttp2/lib/nghttp2_session.c
index 004a4dff..008f9d34 100644
--- a/deps/nghttp2/lib/nghttp2_session.c
+++ b/deps/nghttp2/lib/nghttp2_session.c
@@ -1485,6 +1485,11 @@ int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id,

DEBUGF("stream: stream(%p)=%d close\n", stream, stream->stream_id);

+ if (error_code == NGHTTP2_NO_ERROR &&
+ nghttp2_http_on_remote_end_stream(stream) == -1) {
+ error_code = NGHTTP2_PROTOCOL_ERROR;
+ }
+
/* We call on_stream_close_callback even if stream->state is
NGHTTP2_STREAM_INITIAL. This will happen while sending request
HEADERS, a local endpoint receives RST_STREAM for that stream. It
--
2.40.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 9581880841f5afa00075eb6089389c03015334ce Mon Sep 17 00:00:00 2001
From: Szymon Marczak <[email protected]>
Date: Fri, 4 Oct 2024 08:08:15 +0200
Subject: [PATCH] Check if session_call_on_frame_received frees the stream in
session_after_header_block_received

---
deps/nghttp2/lib/nghttp2_session.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/deps/nghttp2/lib/nghttp2_session.c b/deps/nghttp2/lib/nghttp2_session.c
index 08efaf0f8e..8b818c30a2 100644
--- a/deps/nghttp2/lib/nghttp2_session.c
+++ b/deps/nghttp2/lib/nghttp2_session.c
@@ -4186,6 +4186,11 @@ static int session_after_header_block_received(nghttp2_session *session) {
return 0;
}

+ /* on_frame might free the stream */
+ if (!nghttp2_session_get_stream(session, frame->hd.stream_id)) {
+ return 0;
+ }
+
return session_end_stream_headers_received(session, frame, stream);
}

--
2.46.2

26 changes: 26 additions & 0 deletions deps/nghttp2/patches/0002-rst-before-goaway.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From a990ac8598241f939ca41bf7a7c53c40094663bf Mon Sep 17 00:00:00 2001
From: Szymon Marczak <[email protected]>
Date: Fri, 4 Oct 2024 11:52:30 +0200
Subject: [PATCH] Allow RST_STREAM before GOAWAY

---
deps/nghttp2/lib/nghttp2_session.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/deps/nghttp2/lib/nghttp2_session.c b/deps/nghttp2/lib/nghttp2_session.c
index 8b818c30a2..67d8b08d36 100644
--- a/deps/nghttp2/lib/nghttp2_session.c
+++ b/deps/nghttp2/lib/nghttp2_session.c
@@ -2521,9 +2521,6 @@ static int session_prep_frame(nghttp2_session *session,
return 0;
}
case NGHTTP2_RST_STREAM:
- if (session_is_closing(session)) {
- return NGHTTP2_ERR_SESSION_CLOSING;
- }
nghttp2_frame_pack_rst_stream(&session->aob.framebufs, &frame->rst_stream);
return 0;
case NGHTTP2_SETTINGS: {
--
2.46.2

2 changes: 1 addition & 1 deletion doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ added: v8.4.0
due to an error.
* `code` {number} The HTTP/2 error code to send in the final `GOAWAY` frame.
If unspecified, and `error` is not undefined, the default is `INTERNAL_ERROR`,
otherwise defaults to `NO_ERROR`.
otherwise defaults to `CANCEL`.

Immediately terminates the `Http2Session` and the associated `net.Socket` or
`tls.TLSSocket`.
Expand Down
Loading
Loading