diff options
author | Matteo Collina <hello@matteocollina.com> | 2016-05-17 12:36:54 +0200 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2016-05-26 11:28:45 +0200 |
commit | c14e98b476156487024254fe391512ae95e642e6 (patch) | |
tree | ec347be28eafb9cb8f30a52d4ca66d074fe5dc32 /test/parallel/test-dgram-send-callback-multi-buffer.js | |
parent | f9ea52e5ebebf4ad7058ff1d950c63ae18a7a3da (diff) | |
download | android-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-callback-multi-buffer.js')
-rw-r--r-- | test/parallel/test-dgram-send-callback-multi-buffer.js | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/test/parallel/test-dgram-send-callback-multi-buffer.js b/test/parallel/test-dgram-send-callback-multi-buffer.js index c2a1a53e00..8e4870fbcb 100644 --- a/test/parallel/test-dgram-send-callback-multi-buffer.js +++ b/test/parallel/test-dgram-send-callback-multi-buffer.js @@ -10,23 +10,22 @@ const timer = setTimeout(function() { throw new Error('Timeout'); }, common.platformTimeout(200)); -const onMessage = common.mustCall(function(err, bytes) { +const messageSent = common.mustCall(function messageSent(err, bytes) { assert.equal(bytes, buf1.length + buf2.length); clearTimeout(timer); - client.close(); }); const buf1 = Buffer.alloc(256, 'x'); const buf2 = Buffer.alloc(256, 'y'); client.on('listening', function() { - client.send([buf1, buf2], common.PORT, common.localhostIPv4, onMessage); + client.send([buf1, buf2], common.PORT, common.localhostIPv4, messageSent); }); -client.on('message', function(buf, info) { +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); |