GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: guard against null write request on cancelled stream · nodejs/node@22f4367

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • stream_base.cc
  • test/parallel
    • test-http2-respond-with-file-cancelled-crash.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/stream_base.cc‎

Copy file name to clipboardExpand all lines: src/stream_base.cc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
799799
void ReportWritesToJSStreamListener::OnStreamAfterReqFinished(
800800
StreamReq* req_wrap, int status) {
801801
StreamBase* stream = static_cast<StreamBase*>(stream_);
802+
if (stream == nullptr) return;
803+
if (req_wrap == nullptr) return;
802804
Environment* env = stream->stream_env();
803805
if (!env->can_call_into_js()) return;
804806
AsyncWrap* async_wrap = req_wrap->GetAsyncWrap();
Collapse file

‎test/parallel/test-http2-respond-with-file-cancelled-crash.js‎

Copy file name to clipboard
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
// Regression test for https://hackerone.com/4150894 (NULL dereference in
4+
// StreamPipe). Cancelling an in-flight `respondWithFile()` download while a
5+
// file read is still pending on the thread pool crashed the server: a NULL
6+
// WriteWrap was forwarded to ReportWritesToJSStreamListener, which then
7+
// dereferenced it in OnStreamAfterReqFinished().
8+
9+
const common = require('../common');
10+
if (!common.hasCrypto)
11+
common.skip('missing crypto');
12+
const http2 = require('http2');
13+
14+
const server = http2.createServer();
15+
server.on('stream', (stream) => {
16+
stream.on('error', () => {});
17+
// Use a file large enough that a read is still in flight when the client
18+
// destroys the session.
19+
stream.respondWithFile(process.execPath);
20+
});
21+
server.on('sessionError', () => {});
22+
23+
server.listen(0, common.mustCall(() => {
24+
const port = server.address().port;
25+
const rounds = 50;
26+
let i = 0;
27+
let done = false;
28+
29+
function cancelOne() {
30+
if (done) return;
31+
if (i >= rounds) {
32+
done = true;
33+
server.close(common.mustCall());
34+
return;
35+
}
36+
i++;
37+
const client = http2.connect(`http://127.0.0.1:${port}`);
38+
client.on('error', () => {});
39+
const req = client.request({ ':path': '/' });
40+
req.on('error', () => {});
41+
req.resume();
42+
// Destroy the session shortly after the request is sent, while the server
43+
// may still be reading the file. Vary the delay to hit the race window.
44+
setTimeout(() => {
45+
client.destroy();
46+
setTimeout(cancelOne, 1);
47+
}, 3 + (i * 7) % 40);
48+
}
49+
50+
cancelOne();
51+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.