From 9efae47ac01978955fd5233f010408eb71da4ed1 Mon Sep 17 00:00:00 2001
From: Guillaume Burel <guillaume.burel@stormshield.eu>
Date: Sun, 13 Jan 2019 07:35:49 +0800
Subject: [PATCH] Subject: [PATCH] Fix control messages are inflated

RFC7692 states that control messages should not be compressed so there is no
need to inflate these messages.

There can be a bug if a control message is received while processing a
compressed message since lws relies on the RSV bit of the first message to
inflate the rx buffer or not.
Here we also check the opcode to only inflate a message if it is a data message.

Fixes: #1470
---
 lib/roles/ws/ext/extension-permessage-deflate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/roles/ws/ext/extension-permessage-deflate.c b/lib/roles/ws/ext/extension-permessage-deflate.c
index b832d1d2..98ad04a4 100644
--- a/lib/roles/ws/ext/extension-permessage-deflate.c
+++ b/lib/roles/ws/ext/extension-permessage-deflate.c
@@ -179,7 +179,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context,
 	case LWS_EXT_CB_PAYLOAD_RX:
 		lwsl_ext(" %s: LWS_EXT_CB_PAYLOAD_RX: in %d, existing in %d\n",
 			 __func__, ebuf->len, priv->rx.avail_in);
-		if (!(wsi->ws->rsv_first_msg & 0x40))
+		if (!(wsi->ws->rsv_first_msg & 0x40) || (wsi->ws->opcode & 8))
 			return 0;
 
 		// lwsl_hexdump_debug(ebuf->token, ebuf->len);
-- 
GitLab