From: David Cermak Date: Tue, 16 Jul 2019 07:47:18 +0000 (+0200) Subject: tcp_tansport: websocket layer modifies in-buffer data (for masked transports). This... X-Git-Tag: v4.0-beta1~34^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8fc02e860a2842a0ce023076a4bb1e42323f68d4;p=esp-idf tcp_tansport: websocket layer modifies in-buffer data (for masked transports). This fix reverts the data back to original rather then making a copy. Closes https://github.com/espressif/esp-idf/issues/3774 --- diff --git a/components/tcp_transport/transport_ws.c b/components/tcp_transport/transport_ws.c index 599457b895..12aaa3d232 100644 --- a/components/tcp_transport/transport_ws.c +++ b/components/tcp_transport/transport_ws.c @@ -208,7 +208,17 @@ static int _ws_write(esp_transport_handle_t t, int opcode, int mask_flag, const if (len == 0) { return 0; } - return esp_transport_write(ws->parent, buffer, len, timeout_ms); + + int ret = esp_transport_write(ws->parent, buffer, len, timeout_ms); + // in case of masked transport we have to revert back to the original data, as ws layer + // does not create its own copy of data to be sent + if (mask_flag) { + mask = &ws_header[header_len-4]; + for (i = 0; i < len; ++i) { + buffer[i] = (buffer[i] ^ mask[i % 4]); + } + } + return ret; } static int ws_write(esp_transport_handle_t t, const char *b, int len, int timeout_ms)