Skip to content

Commit 0ab90ac

Browse files
jasnellevanlucas
authored andcommitted
test: add regression test for nghttp2 CVE-2018-1000168
PR-URL: https://github.com/nodejs-private/node-private/pull/124 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 65ed321 commit 0ab90ac

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/common/http2.js

+10
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,18 @@ class PingFrame extends Frame {
127127
}
128128
}
129129

130+
class AltSvcFrame extends Frame {
131+
constructor(size) {
132+
const buffers = [Buffer.alloc(size)];
133+
super(size, 10, 0, 0);
134+
buffers.unshift(this[kFrameData]);
135+
this[kFrameData] = Buffer.concat(buffers);
136+
}
137+
}
138+
130139
module.exports = {
131140
Frame,
141+
AltSvcFrame,
132142
DataFrame,
133143
HeadersFrame,
134144
SettingsFrame,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
8+
const http2 = require('http2');
9+
const net = require('net');
10+
const h2test = require('../common/http2');
11+
12+
const server = http2.createServer();
13+
server.on('stream', common.mustNotCall());
14+
15+
const settings = new h2test.SettingsFrame();
16+
const settingsAck = new h2test.SettingsFrame(true);
17+
const altsvc = new h2test.AltSvcFrame((1 << 14) + 1);
18+
19+
server.listen(0, () => {
20+
const client = net.connect(server.address().port, () => {
21+
client.write(h2test.kClientMagic, () => {
22+
client.write(settings.data, () => {
23+
client.write(settingsAck.data);
24+
// Prior to nghttp2 1.31.1, sending this malformed altsvc frame
25+
// would cause a segfault. This test is successful if a segfault
26+
// does not occur.
27+
client.write(altsvc.data, common.mustCall(() => {
28+
client.destroy();
29+
}));
30+
});
31+
});
32+
});
33+
34+
// An error may or may not be emitted on the client side, we don't care
35+
// either way if it is, but we don't want to die if it is.
36+
client.on('error', () => {});
37+
client.on('close', common.mustCall(() => server.close()));
38+
client.resume();
39+
});

0 commit comments

Comments
 (0)