Skip to content

Commit 47eecd2

Browse files
committed
fixup! do not reverse in place, add a test for it.
1 parent 36fb6f1 commit 47eecd2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/_tls_wrap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,8 @@ Server.prototype[EE.captureRejectionSymbol] = function(
14351435

14361436
function SNICallback(servername, callback) {
14371437
const contexts = this.server._contexts;
1438-
1439-
for (const elem of contexts.reverse()) {
1438+
for (let i = contexts.length - 1; i >= 0; --i) {
1439+
const elem = contexts[i];
14401440
if (elem[0].test(servername)) {
14411441
callback(null, elem[1]);
14421442
return;

test/parallel/test-tls-secure-context-usage-order.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,17 @@ server.listen(0, () => {
8383
});
8484

8585
other.on('close', common.mustCall(() => {
86-
server.close();
86+
// 5. Make another connection using servername 'b.example.com' to ensure
87+
// that the array of secure contexts is not reversed in place with each
88+
// SNICallback call, as someone might be tempted to refactor this piece of
89+
// code by using Array.prototype.reverse() method.
90+
const onemore = tls.connect(options, () => {
91+
onemore.end();
92+
});
93+
94+
onemore.on('close', common.mustCall(() => {
95+
server.close();
96+
}));
8797
}));
8898
}));
8999
});

0 commit comments

Comments
 (0)