dgram: fix regression in string argument handling
authorBen Noordhuis <info@bnoordhuis.nl>
Fri, 9 Aug 2013 00:33:40 +0000 (02:33 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Fri, 9 Aug 2013 01:05:46 +0000 (03:05 +0200)
commit41ec6d0580d91c4f2e5f30f279225eb4ec07886d
treecaa16d3cb5a3c3ddae2a5d98ef3fb284cc230a5c
parentf674b09f40d22915e15b6968aafc5d25ac8178a2
dgram: fix regression in string argument handling

v0.10 allows strings for the offset, length and port arguments to
dgram.send() and dgram.sendto() but master before this commit would
abort with the following assert:

    node: ../../src/udp_wrap.cc:227: static void
    node::UDPWrap::DoSend(const v8::FunctionCallbackInfo<v8::Value>&,
    int): Assertion `args[2]->IsUint32()' failed.

Go beyond what v0.10 does and also add range checks: offset and length
should be >= 0, port should be between 1 and 65535.

That particular change needs to be back-ported to v0.10 because passing
a negative offset or length number aborts with the following assertions:

    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.

Or:

    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 is accepted in v0.10 but
is silently ignored.

This commit exposed a bug in the simple/test-dgram-close test which
has also been fixed.
lib/dgram.js
test/simple/test-dgram-close.js
test/simple/test-dgram-send-bad-arguments.js [new file with mode: 0644]