Skip to content

Commit d5cdc12

Browse files
efekrskladuh95
authored andcommitted
http: guard invalid timeout values in checkConnections
Signed-off-by: Efe Karasakal <hi@efe.dev> PR-URL: #64506 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Tim Perry <pimterry@gmail.com>
1 parent b2762a1 commit d5cdc12

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/_http_server.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,18 @@ assignFunctionName(EE.captureRejectionSymbol, function(err, event, ...args) {
739739
});
740740

741741
function checkConnections() {
742-
if (this.headersTimeout === 0 && this.requestTimeout === 0) {
742+
const headersTimeout =
743+
NumberIsFinite(this.headersTimeout) && this.headersTimeout >= 0 ?
744+
this.headersTimeout : 0;
745+
const requestTimeout =
746+
NumberIsFinite(this.requestTimeout) && this.requestTimeout >= 0 ?
747+
this.requestTimeout : 0;
748+
749+
if (headersTimeout === 0 && requestTimeout === 0) {
743750
return;
744751
}
745752

746-
const expired = this[kConnections].expired(this.headersTimeout, this.requestTimeout);
753+
const expired = this[kConnections].expired(headersTimeout, requestTimeout);
747754

748755
for (let i = 0; i < expired.length; i++) {
749756
const socket = expired[i].socket;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const { createServer } = require('http');
6+
7+
const server = createServer({
8+
connectionsCheckingInterval: 1,
9+
}, common.mustNotCall());
10+
11+
// Invalid headersTimeout should not crash the server
12+
server.headersTimeout = 'im-not-a-number';
13+
assert.strictEqual(server.headersTimeout, 'im-not-a-number');
14+
15+
server.listen(0, '127.0.0.1', common.mustCall(() => {
16+
setTimeout(common.mustCall(() => {
17+
server.close(common.mustCall());
18+
}), common.platformTimeout(50));
19+
}));

0 commit comments

Comments
 (0)