Blame SOURCES/kvm-io-Allow-empty-websocket-payload.patch

9bac43
From 56192448a2221f518f3e959f511e1244100de600 Mon Sep 17 00:00:00 2001
9bac43
From: "Daniel P. Berrange" <berrange@redhat.com>
9bac43
Date: Wed, 20 Dec 2017 17:56:49 +0100
9bac43
Subject: [PATCH 09/42] io: Allow empty websocket payload
9bac43
9bac43
RH-Author: Daniel P. Berrange <berrange@redhat.com>
9bac43
Message-id: <20171220175702.29663-8-berrange@redhat.com>
9bac43
Patchwork-id: 78453
9bac43
O-Subject: [RHV-7.5 qemu-kvm-rhev PATCH v2 07/20] io: Allow empty websocket payload
9bac43
Bugzilla: 1518649
9bac43
RH-Acked-by: John Snow <jsnow@redhat.com>
9bac43
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9bac43
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
From: Brandon Carpenter <brandon.carpenter@cypherpath.com>
9bac43
9bac43
Some browsers send pings/pongs with no payload, so allow empty payloads
9bac43
instead of closing the connection.
9bac43
9bac43
Signed-off-by: Brandon Carpenter <brandon.carpenter@cypherpath.com>
9bac43
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
9bac43
(cherry picked from commit 3a29640e2cbae9d47b89ffaf98ed358920eb6797)
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 io/channel-websock.c | 62 +++++++++++++++++++++++++---------------------------
9bac43
 1 file changed, 30 insertions(+), 32 deletions(-)
9bac43
9bac43
diff --git a/io/channel-websock.c b/io/channel-websock.c
9bac43
index 909d636..b19b5d9 100644
9bac43
--- a/io/channel-websock.c
9bac43
+++ b/io/channel-websock.c
9bac43
@@ -697,44 +697,42 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,
9bac43
                                               Error **errp)
9bac43
 {
9bac43
     size_t i;
9bac43
-    size_t payload_len;
9bac43
+    size_t payload_len = 0;
9bac43
     uint32_t *payload32;
9bac43
 
9bac43
-    if (!ioc->payload_remain) {
9bac43
-        error_setg(errp,
9bac43
-                   "Decoding payload but no bytes of payload remain");
9bac43
-        return -1;
9bac43
-    }
9bac43
-
9bac43
-    /* If we aren't at the end of the payload, then drop
9bac43
-     * off the last bytes, so we're always multiple of 4
9bac43
-     * for purpose of unmasking, except at end of payload
9bac43
-     */
9bac43
-    if (ioc->encinput.offset < ioc->payload_remain) {
9bac43
-        payload_len = ioc->encinput.offset - (ioc->encinput.offset % 4);
9bac43
-    } else {
9bac43
-        payload_len = ioc->payload_remain;
9bac43
-    }
9bac43
-    if (payload_len == 0) {
9bac43
-        return QIO_CHANNEL_ERR_BLOCK;
9bac43
-    }
9bac43
+    if (ioc->payload_remain) {
9bac43
+        /* If we aren't at the end of the payload, then drop
9bac43
+         * off the last bytes, so we're always multiple of 4
9bac43
+         * for purpose of unmasking, except at end of payload
9bac43
+         */
9bac43
+        if (ioc->encinput.offset < ioc->payload_remain) {
9bac43
+            payload_len = ioc->encinput.offset - (ioc->encinput.offset % 4);
9bac43
+        } else {
9bac43
+            payload_len = ioc->payload_remain;
9bac43
+        }
9bac43
+        if (payload_len == 0) {
9bac43
+            return QIO_CHANNEL_ERR_BLOCK;
9bac43
+        }
9bac43
 
9bac43
-    ioc->payload_remain -= payload_len;
9bac43
+        ioc->payload_remain -= payload_len;
9bac43
 
9bac43
-    /* unmask frame */
9bac43
-    /* process 1 frame (32 bit op) */
9bac43
-    payload32 = (uint32_t *)ioc->encinput.buffer;
9bac43
-    for (i = 0; i < payload_len / 4; i++) {
9bac43
-        payload32[i] ^= ioc->mask.u;
9bac43
-    }
9bac43
-    /* process the remaining bytes (if any) */
9bac43
-    for (i *= 4; i < payload_len; i++) {
9bac43
-        ioc->encinput.buffer[i] ^= ioc->mask.c[i % 4];
9bac43
+        /* unmask frame */
9bac43
+        /* process 1 frame (32 bit op) */
9bac43
+        payload32 = (uint32_t *)ioc->encinput.buffer;
9bac43
+        for (i = 0; i < payload_len / 4; i++) {
9bac43
+            payload32[i] ^= ioc->mask.u;
9bac43
+        }
9bac43
+        /* process the remaining bytes (if any) */
9bac43
+        for (i *= 4; i < payload_len; i++) {
9bac43
+            ioc->encinput.buffer[i] ^= ioc->mask.c[i % 4];
9bac43
+        }
9bac43
     }
9bac43
 
9bac43
-    buffer_reserve(&ioc->rawinput, payload_len);
9bac43
-    buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len);
9bac43
-    buffer_advance(&ioc->encinput, payload_len);
9bac43
+    if (payload_len) {
9bac43
+        buffer_reserve(&ioc->rawinput, payload_len);
9bac43
+        buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len);
9bac43
+        buffer_advance(&ioc->encinput, payload_len);
9bac43
+    }
9bac43
     return 0;
9bac43
 }
9bac43
 
9bac43
-- 
9bac43
1.8.3.1
9bac43