dgram: fix assertion on bad send() arguments
authorBen Noordhuis <info@bnoordhuis.nl>
Fri, 9 Aug 2013 00:33:40 +0000 (02:33 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Sat, 17 Aug 2013 15:11:02 +0000 (17:11 +0200)
commit0c2960ef4ab83f0eef2fc60c2575403c33ba4c6b
tree88755b7118635ecddff8511bf56d60700499910e
parent5453619eb2a3bb3e5cae1c1379e3985c724e12c6
dgram: fix assertion on bad send() arguments

Add range checks for the offset, length and port arguments to
dgram.Socket#send().  Fixes the following assertion:

    node: ../../src/udp_wrap.cc:264: static v8::Handle<v8::Value>
    node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion
    `offset < Buffer::Length(buffer_obj)' failed.

And:

    node: ../../src/udp_wrap.cc:265: static v8::Handle<v8::Value>
    node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion
    `length <= Buffer::Length(buffer_obj) - offset' failed.

Interestingly enough, a negative port number was accepted until now but
silently ignored.  (In other words, it would send the datagram to a
random port.)

This commit exposed a bug in the simple/test-dgram-close test which
has also been fixed.

This is a back-port of commit 41ec6d0 from the master branch.

Fixes #6025.
lib/dgram.js
test/simple/test-dgram-close.js
test/simple/test-dgram-send-bad-arguments.js [new file with mode: 0644]