Skip to content

Commit 20616f1

Browse files
Renegade334marco-ippolito
authored andcommitted
http2: do not crash on mismatched ping buffer length
PR-URL: #60135 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3456ec9 commit 20616f1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/internal/http2/core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,9 +1414,9 @@ class Http2Session extends EventEmitter {
14141414
}
14151415
if (payload) {
14161416
validateBuffer(payload, 'payload');
1417-
}
1418-
if (payload && payload.length !== 8) {
1419-
throw new ERR_HTTP2_PING_LENGTH();
1417+
if (payload.byteLength !== 8) {
1418+
throw new ERR_HTTP2_PING_LENGTH();
1419+
}
14201420
}
14211421
validateFunction(callback, 'callback');
14221422

test/parallel/test-http2-ping.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ server.listen(0, common.mustCall(() => {
6464
})));
6565
}
6666
{
67-
const payload = Buffer.from('abcdefgi');
67+
const payload = new Uint16Array([1, 2, 3, 4]);
6868
assert(client.ping(payload, common.mustCall((err, duration, ret) => {
6969
assert.strictEqual(err, null);
7070
assert.strictEqual(typeof duration, 'number');
71-
assert.deepStrictEqual(payload, ret);
71+
assert.deepStrictEqual(payload.buffer, ret.buffer);
7272
})));
7373
}
7474

@@ -99,7 +99,8 @@ server.listen(0, common.mustCall(() => {
9999
{
100100
const shortPayload = Buffer.from('abcdefg');
101101
const longPayload = Buffer.from('abcdefghi');
102-
[shortPayload, longPayload].forEach((payloadWithInvalidLength) =>
102+
const mismatchedPayload = new Uint32Array(8);
103+
[shortPayload, longPayload, mismatchedPayload].forEach((payloadWithInvalidLength) =>
103104
assert.throws(
104105
() => client.ping(payloadWithInvalidLength),
105106
{

0 commit comments

Comments
 (0)