node/test/parallel/test-dgram-send-empty-buffer.js
Matteo Collina c14e98b476 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>
2016-05-26 11:28:45 +02:00

25 lines
578 B
JavaScript

'use strict';
const common = require('../common');
const dgram = require('dgram');
if (process.platform === 'darwin') {
common.skip('because of 17894467 Apple bug');
return;
}
const client = dgram.createSocket('udp4');
client.bind(common.PORT);
client.on('message', common.mustCall(function onMessage(buffer, bytes) {
clearTimeout(timer);
client.close();
}));
const buf = Buffer.alloc(0);
client.send(buf, 0, 0, common.PORT, '127.0.0.1', function(err, len) { });
const timer = setTimeout(function() {
throw new Error('Timeout');
}, common.platformTimeout(200));