From 0c2bcea779a76bbe3d4b31b13ea0cac6f7ab532c Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Wed, 29 Sep 2021 08:42:47 -0400 Subject: [PATCH] mutation done now to mask so a copy is necessary. can maybe optimize later but this avoids mem prot errors when passed string literals and other surprised when pssed temporaries --- cgi.d | 8 ++++---- http2.d | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cgi.d b/cgi.d index fed327a..d38063e 100644 --- a/cgi.d +++ b/cgi.d @@ -5610,7 +5610,7 @@ version(cgi_with_websocket) { WebSocketFrame wss; wss.fin = true; wss.opcode = WebSocketOpcode.close; - wss.data = cast(ubyte[]) reason; + wss.data = cast(ubyte[]) reason.dup; wss.send(&llsend); readyState_ = CLOSING; @@ -5645,7 +5645,7 @@ version(cgi_with_websocket) { WebSocketFrame wss; wss.fin = true; wss.opcode = WebSocketOpcode.text; - wss.data = cast(ubyte[]) textData; + wss.data = cast(ubyte[]) textData.dup; wss.send(&llsend); } @@ -5657,7 +5657,7 @@ version(cgi_with_websocket) { WebSocketFrame wss; wss.fin = true; wss.opcode = WebSocketOpcode.binary; - wss.data = cast(ubyte[]) binaryData; + wss.data = cast(ubyte[]) binaryData.dup; wss.send(&llsend); } @@ -5895,7 +5895,7 @@ version(cgi_with_websocket) { WebSocketFrame msg; msg.fin = true; msg.opcode = opcode; - msg.data = cast(ubyte[]) data; + msg.data = cast(ubyte[]) data.dup; return msg; } diff --git a/http2.d b/http2.d index 95e03cd..0ebcbdc 100644 --- a/http2.d +++ b/http2.d @@ -3696,7 +3696,7 @@ class WebSocket { WebSocketFrame wss; wss.fin = true; wss.opcode = WebSocketOpcode.close; - wss.data = cast(ubyte[]) reason; + wss.data = cast(ubyte[]) reason.dup; wss.send(&llsend); readyState_ = CLOSING; @@ -3732,7 +3732,7 @@ class WebSocket { wss.fin = true; wss.masked = this.isClient; wss.opcode = WebSocketOpcode.text; - wss.data = cast(ubyte[]) textData; + wss.data = cast(ubyte[]) textData.dup; wss.send(&llsend); } @@ -3745,7 +3745,7 @@ class WebSocket { wss.masked = this.isClient; wss.fin = true; wss.opcode = WebSocketOpcode.binary; - wss.data = cast(ubyte[]) binaryData; + wss.data = cast(ubyte[]) binaryData.dup; wss.send(&llsend); } @@ -4065,11 +4065,11 @@ public { ubyte[4] maskingKey; // don't set this when sending ubyte[] data; - static WebSocketFrame simpleMessage(WebSocketOpcode opcode, void[] data) { + static WebSocketFrame simpleMessage(WebSocketOpcode opcode, in void[] data) { WebSocketFrame msg; msg.fin = true; msg.opcode = opcode; - msg.data = cast(ubyte[]) data; + msg.data = cast(ubyte[]) data.dup; // it is mutated below when masked, so need to be cautious and copy it, sigh return msg; }