summaryrefslogtreecommitdiff
path: root/test/parallel/test-net-socket-timeout.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2014-12-16 17:17:28 -0500
committercjihrig <cjihrig@gmail.com>2015-02-13 13:37:24 -0500
commit0cff0521c333df8649bc6a2b1f40adbf899b1261 (patch)
treee340b83cdfd414829abd13220eb16af1c87366ef /test/parallel/test-net-socket-timeout.js
parentba40942ad22c8dd0dc7699370c6d3867c99267bc (diff)
downloadandroid-node-v8-0cff0521c333df8649bc6a2b1f40adbf899b1261.tar.gz
android-node-v8-0cff0521c333df8649bc6a2b1f40adbf899b1261.tar.bz2
android-node-v8-0cff0521c333df8649bc6a2b1f40adbf899b1261.zip
net: throw on invalid socket timeouts
This commit restricts socket timeouts non-negative, finite numbers. Any other value throws a TypeError or RangeError. This prevents subtle bugs that can happen due to type coercion. Fixes: https://github.com/joyent/node/issues/8618 PR-URL: https://github.com/joyent/node/pull/8884 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com> Conflicts: lib/timers.js test/simple/test-net-settimeout.js test/simple/test-net-socket-timeout.js
Diffstat (limited to 'test/parallel/test-net-socket-timeout.js')
-rw-r--r--test/parallel/test-net-socket-timeout.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/parallel/test-net-socket-timeout.js b/test/parallel/test-net-socket-timeout.js
index c4d84fa177..f403829876 100644
--- a/test/parallel/test-net-socket-timeout.js
+++ b/test/parallel/test-net-socket-timeout.js
@@ -2,6 +2,31 @@ var common = require('../common');
var net = require('net');
var assert = require('assert');
+// Verify that invalid delays throw
+var noop = function() {};
+var s = new net.Socket();
+var nonNumericDelays = ['100', true, false, undefined, null, '', {}, noop, []];
+var badRangeDelays = [-0.001, -1, -Infinity, Infinity, NaN];
+var validDelays = [0, 0.001, 1, 1e6];
+
+for (var i = 0; i < nonNumericDelays.length; i++) {
+ assert.throws(function() {
+ s.setTimeout(nonNumericDelays[i], noop);
+ }, TypeError);
+}
+
+for (var i = 0; i < badRangeDelays.length; i++) {
+ assert.throws(function() {
+ s.setTimeout(badRangeDelays[i], noop);
+ }, RangeError);
+}
+
+for (var i = 0; i < validDelays.length; i++) {
+ assert.doesNotThrow(function() {
+ s.setTimeout(validDelays[i], noop);
+ });
+}
+
var timedout = false;
var server = net.Server();