From 93fd4bc18a81a568f3329ee2aa22390ef75b05ed Mon Sep 17 00:00:00 2001
From: plettix <plettix@gmail.com>
Date: Tue, 7 Jul 2015 10:32:16 +0200
Subject: [PATCH 2/3] fix for issue 81 use different buffers for decode and
encode
---
libvncserver/websockets.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/libvncserver/websockets.c b/libvncserver/websockets.c
index 937f6d4d..3c8e99aa 100644
--- a/libvncserver/websockets.c
+++ b/libvncserver/websockets.c
@@ -481,15 +481,15 @@ webSocketsEncodeHixie(rfbClientPtr cl, const char *src, int len, char **dst)
int sz = 0;
ws_ctx_t *wsctx = (ws_ctx_t *)cl->wsctx;
- wsctx->codeBuf[sz++] = '\x00';
- len = __b64_ntop((unsigned char *)src, len, wsctx->codeBuf+sz, sizeof(wsctx->codeBuf) - (sz + 1));
+ wsctx->codeBufEncode[sz++] = '\x00';
+ len = __b64_ntop((unsigned char *)src, len, wsctx->codeBufEncode+sz, sizeof(wsctx->codeBufEncode) - (sz + 1));
if (len < 0) {
return len;
}
sz += len;
- wsctx->codeBuf[sz++] = '\xff';
- *dst = wsctx->codeBuf;
+ wsctx->codeBufEncode[sz++] = '\xff';
+ *dst = wsctx->codeBufEncode;
return sz;
}
@@ -527,7 +527,7 @@ webSocketsDecodeHixie(rfbClientPtr cl, char *dst, int len)
char *buf, *end = NULL;
ws_ctx_t *wsctx = (ws_ctx_t *)cl->wsctx;
- buf = wsctx->codeBuf;
+ buf = wsctx->codeBufDecode;
n = ws_peek(cl, buf, len*2+2);
@@ -781,7 +781,7 @@ webSocketsEncodeHybi(rfbClientPtr cl, const char *src, int len, char **dst)
return 0;
}
- header = (ws_header_t *)wsctx->codeBuf;
+ header = (ws_header_t *)wsctx->codeBufEncode;
if (wsctx->base64) {
opcode = WS_OPCODE_TEXT_FRAME;
@@ -806,7 +806,7 @@ webSocketsEncodeHybi(rfbClientPtr cl, const char *src, int len, char **dst)
}
if (wsctx->base64) {
- if (-1 == (ret = __b64_ntop((unsigned char *)src, len, wsctx->codeBuf + sz, sizeof(wsctx->codeBuf) - sz))) {
+ if (-1 == (ret = __b64_ntop((unsigned char *)src, len, wsctx->codeBufEncode + sz, sizeof(wsctx->codeBufEncode) - sz))) {
rfbErr("%s: Base 64 encode failed\n", __func__);
} else {
if (ret != blen)
@@ -814,11 +814,12 @@ webSocketsEncodeHybi(rfbClientPtr cl, const char *src, int len, char **dst)
ret += sz;
}
} else {
- memcpy(wsctx->codeBuf + sz, src, len);
+ memcpy(wsctx->codeBufEncode + sz, src, len);
ret = sz + len;
}
- *dst = wsctx->codeBuf;
+ *dst = wsctx->codeBufEncode;
+
return ret;
}
--
2.26.2