more bugs in websocket

This commit is contained in:
Adam D. Ruppe 2020-01-12 09:31:55 -05:00
parent 7b5e7eb2c4
commit 059481bff2
1 changed files with 17 additions and 4 deletions

21
http2.d
View File

@ -2583,7 +2583,7 @@ wss://echo.websocket.org
throw new Exception("message size exceeded"); throw new Exception("message size exceeded");
continuingData ~= m.data; continuingData ~= m.data;
if(fin) { if(m.fin) {
if(ontextmessage) if(ontextmessage)
ontextmessage(cast(char[]) continuingData); ontextmessage(cast(char[]) continuingData);
if(onbinarymessage) if(onbinarymessage)
@ -2856,10 +2856,17 @@ private {
static WebSocketFrame read(ref ubyte[] d) { static WebSocketFrame read(ref ubyte[] d) {
WebSocketFrame msg; WebSocketFrame msg;
assert(d.length >= 2);
auto orig = d; auto orig = d;
WebSocketFrame needsMoreData() {
d = orig;
return WebSocketFrame.init;
}
if(d.length < 2)
return needsMoreData();
ubyte b = d[0]; ubyte b = d[0];
msg.populated = true; msg.populated = true;
@ -2884,6 +2891,8 @@ private {
// 16 bit length // 16 bit length
msg.realLength = 0; msg.realLength = 0;
if(d.length < 2) return needsMoreData();
foreach(i; 0 .. 2) { foreach(i; 0 .. 2) {
msg.realLength |= d[0] << ((1-i) * 8); msg.realLength |= d[0] << ((1-i) * 8);
d = d[1 .. $]; d = d[1 .. $];
@ -2892,6 +2901,8 @@ private {
// 64 bit length // 64 bit length
msg.realLength = 0; msg.realLength = 0;
if(d.length < 8) return needsMoreData();
foreach(i; 0 .. 8) { foreach(i; 0 .. 8) {
msg.realLength |= d[0] << ((7-i) * 8); msg.realLength |= d[0] << ((7-i) * 8);
d = d[1 .. $]; d = d[1 .. $];
@ -2902,13 +2913,15 @@ private {
} }
if(msg.masked) { if(msg.masked) {
if(d.length < 4) return needsMoreData();
msg.maskingKey = d[0 .. 4]; msg.maskingKey = d[0 .. 4];
d = d[4 .. $]; d = d[4 .. $];
} }
if(msg.realLength > d.length) { if(msg.realLength > d.length) {
d = orig; return needsMoreData();
return WebSocketFrame.init;
} }
msg.data = d[0 .. msg.realLength]; msg.data = d[0 .. msg.realLength];