Skip to content

Commit 0716944

Browse files
cjihrigBridgeAR
authored andcommitted
dgram: fix abort on bad args
This commit fixes a C++ abort for connected dgram sockets by improving input validation in the JS layer. Fixes: #28126 PR-URL: #28135 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e1fc9b9 commit 0716944

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎lib/dgram.js‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,19 @@ Socket.prototype.send = function(buffer,
561561
port=offset;
562562
address=length;
563563
}
564-
}elseif(typeoflength==='number'){
565-
buffer=sliceBuffer(buffer,offset,length);
566-
if(typeofport==='function'){
567-
callback=port;
568-
port=null;
569-
}elseif(port||address){
570-
thrownewERR_SOCKET_DGRAM_IS_CONNECTED();
571-
}
572564
}else{
573-
callback=offset;
565+
if(typeoflength==='number'){
566+
buffer=sliceBuffer(buffer,offset,length);
567+
if(typeofport==='function'){
568+
callback=port;
569+
port=null;
570+
}
571+
}else{
572+
callback=offset;
573+
}
574+
575+
if(port||address)
576+
thrownewERR_SOCKET_DGRAM_IS_CONNECTED();
574577
}
575578

576579
if(!Array.isArray(buffer)){

‎test/parallel/test-dgram-send-bad-arguments.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ function checkArgs(connected) {
6868
message: 'Already connected'
6969
}
7070
);
71+
72+
common.expectsError(
73+
()=>{sock.send(buf,1234,'127.0.0.1',common.mustNotCall());},
74+
{
75+
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
76+
type: Error,
77+
message: 'Already connected'
78+
}
79+
);
7180
}else{
7281
assert.throws(()=>{sock.send(buf,1,1,-1,host);},RangeError);
7382
assert.throws(()=>{sock.send(buf,1,1,0,host);},RangeError);

0 commit comments

Comments
 (0)