Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 99c033e

Browse filesBrowse files
santigimenojuanarbol
authored andcommitted
src: fix crash on OnStreamRead on Windows
On Windows it's perfectly possible that the `uv_tcp_t` `read_cb` is called with an error and a null `uv_buf_t` if it corresponds to a `UV_HANDLE_ZERO_READ` read. Handle this case without crashing. Fixes: #40764 PR-URL: #45878 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 4cdf000 commit 99c033e
Copy full SHA for 99c033e

File tree

Expand file treeCollapse file tree

2 files changed

+51
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+51
-3
lines changed
Open diff view settings
Collapse file

‎src/stream_base.cc‎

Copy file name to clipboardExpand all lines: src/stream_base.cc
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,10 @@ void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
583583
HandleScope handle_scope(env->isolate());
584584
Context::Scope context_scope(env->context());
585585

586-
// To deal with the case where POLLHUP is received and UV_EOF is returned, as
587-
// libuv returns an empty buffer (on unices only).
588-
if (nread == UV_EOF && buf.base == nullptr) {
586+
// In the case that there's an error and buf is null, return immediately.
587+
// This can happen on unices when POLLHUP is received and UV_EOF is returned
588+
// or when getting an error while performing a UV_HANDLE_ZERO_READ on Windows.
589+
if (buf.base == nullptr && nread < 0) {
589590
stream->CallJSOnreadMethod(nread, Local<ArrayBuffer>());
590591
return;
591592
}
Collapse file
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const { spawn } = require('child_process');
6+
const net = require('net');
7+
8+
if (process.argv[2] === 'child') {
9+
const server = net.createServer(common.mustCall());
10+
server.listen(0, common.mustCall(() => {
11+
process.send({ type: 'ready', data: { port: server.address().port } });
12+
}));
13+
} else {
14+
const cp = spawn(process.execPath,
15+
[__filename, 'child'],
16+
{
17+
stdio: ['ipc', 'inherit', 'inherit']
18+
});
19+
20+
cp.on('exit', common.mustCall((code, signal) => {
21+
assert.strictEqual(code, null);
22+
assert.strictEqual(signal, 'SIGKILL');
23+
}));
24+
25+
cp.on('message', common.mustCall((msg) => {
26+
const { type, data } = msg;
27+
assert.strictEqual(type, 'ready');
28+
const port = data.port;
29+
30+
const conn = net.createConnection({
31+
port,
32+
onread: {
33+
buffer: Buffer.alloc(65536),
34+
callback: () => {},
35+
}
36+
});
37+
38+
conn.on('error', (err) => {
39+
// Error emitted on Windows.
40+
assert.strictEqual(err.code, 'ECONNRESET');
41+
});
42+
43+
conn.on('connect', common.mustCall(() => {
44+
cp.kill('SIGKILL');
45+
}));
46+
}));
47+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.