summaryrefslogtreecommitdiff
path: root/test/parallel/test-dgram-send-multi-buffer-copy.js
diff options
context:
space:
mode:
authorMatteo Collina <hello@matteocollina.com>2016-05-17 12:36:54 +0200
committerMatteo Collina <hello@matteocollina.com>2016-05-26 11:28:45 +0200
commitc14e98b476156487024254fe391512ae95e642e6 (patch)
treeec347be28eafb9cb8f30a52d4ca66d074fe5dc32 /test/parallel/test-dgram-send-multi-buffer-copy.js
parentf9ea52e5ebebf4ad7058ff1d950c63ae18a7a3da (diff)
downloadandroid-node-v8-c14e98b476156487024254fe391512ae95e642e6.tar.gz
android-node-v8-c14e98b476156487024254fe391512ae95e642e6.tar.bz2
android-node-v8-c14e98b476156487024254fe391512ae95e642e6.zip
dgram: copy the list in send
This commit fix a possible crash situation in dgram send(). A crash is possible if an array is passed, and then altered after the send call, as the call to libuv is wrapped in process.nextTick(). It also avoid sending an empty array to libuv by allocating an empty buffer. It also does some cleanup inside send() to increase readability. It removes test flakyness by use common.mustCall and common.platformTimeout. Fixes situations were some events were not asserted to be emitted. Fixes: https://github.com/nodejs/node/issues/6616 PR-URL: https://github.com/nodejs/node/pull/6804 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/parallel/test-dgram-send-multi-buffer-copy.js')
-rw-r--r--test/parallel/test-dgram-send-multi-buffer-copy.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/parallel/test-dgram-send-multi-buffer-copy.js b/test/parallel/test-dgram-send-multi-buffer-copy.js
new file mode 100644
index 0000000000..6ece56e02a
--- /dev/null
+++ b/test/parallel/test-dgram-send-multi-buffer-copy.js
@@ -0,0 +1,33 @@
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+const dgram = require('dgram');
+
+const client = dgram.createSocket('udp4');
+
+const timer = setTimeout(function() {
+ throw new Error('Timeout');
+}, common.platformTimeout(200));
+
+const onMessage = common.mustCall(function(err, bytes) {
+ assert.equal(bytes, buf1.length + buf2.length);
+ clearTimeout(timer);
+});
+
+const buf1 = Buffer.alloc(256, 'x');
+const buf2 = Buffer.alloc(256, 'y');
+
+client.on('listening', function() {
+ const toSend = [buf1, buf2];
+ client.send(toSend, common.PORT, common.localhostIPv4, onMessage);
+ toSend.splice(0, 2);
+});
+
+client.on('message', common.mustCall(function onMessage(buf, info) {
+ const expected = Buffer.concat([buf1, buf2]);
+ assert.ok(buf.equals(expected), 'message was received correctly');
+ client.close();
+}));
+
+client.bind(common.PORT);