Blame SOURCES/kvm-io-cope-with-websock-Connection-header-having-multip.patch

4a2fec
From 16063b60ae69a93169ab06265dc597072d9bd8ed Mon Sep 17 00:00:00 2001
4a2fec
From: "Daniel P. Berrange" <berrange@redhat.com>
4a2fec
Date: Wed, 20 Dec 2017 17:56:59 +0100
4a2fec
Subject: [PATCH 19/42] io: cope with websock 'Connection' header having
4a2fec
 multiple values
4a2fec
4a2fec
RH-Author: Daniel P. Berrange <berrange@redhat.com>
4a2fec
Message-id: <20171220175702.29663-18-berrange@redhat.com>
4a2fec
Patchwork-id: 78470
4a2fec
O-Subject: [RHV-7.5 qemu-kvm-rhev PATCH v2 17/20] io: cope with websock 'Connection' header having multiple values
4a2fec
Bugzilla: 1518649
4a2fec
RH-Acked-by: John Snow <jsnow@redhat.com>
4a2fec
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
The noVNC server sends a header "Connection: keep-alive, Upgrade" which
4a2fec
fails our simple equality test. Split the header on ',', trim whitespace
4a2fec
and then check for 'upgrade' token.
4a2fec
4a2fec
Reviewed-by: Eric Blake <eblake@redhat.com>
4a2fec
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
4a2fec
(cherry picked from commit 6d5d23b00709510d55711661c7ca41408fd9934e)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 io/channel-websock.c | 14 +++++++++++++-
4a2fec
 1 file changed, 13 insertions(+), 1 deletion(-)
4a2fec
4a2fec
diff --git a/io/channel-websock.c b/io/channel-websock.c
4a2fec
index e82b1be..0354845 100644
4a2fec
--- a/io/channel-websock.c
4a2fec
+++ b/io/channel-websock.c
4a2fec
@@ -374,6 +374,9 @@ static void qio_channel_websock_handshake_process(QIOChannelWebsock *ioc,
4a2fec
     size_t nhdrs = G_N_ELEMENTS(hdrs);
4a2fec
     const char *protocols = NULL, *version = NULL, *key = NULL,
4a2fec
         *host = NULL, *connection = NULL, *upgrade = NULL;
4a2fec
+    char **connectionv;
4a2fec
+    bool upgraded = false;
4a2fec
+    size_t i;
4a2fec
 
4a2fec
     nhdrs = qio_channel_websock_extract_headers(ioc, buffer, hdrs, nhdrs, errp);
4a2fec
     if (!nhdrs) {
4a2fec
@@ -440,7 +443,16 @@ static void qio_channel_websock_handshake_process(QIOChannelWebsock *ioc,
4a2fec
         goto bad_request;
4a2fec
     }
4a2fec
 
4a2fec
-    if (strcasecmp(connection, QIO_CHANNEL_WEBSOCK_CONNECTION_UPGRADE) != 0) {
4a2fec
+    connectionv = g_strsplit(connection, ",", 0);
4a2fec
+    for (i = 0; connectionv != NULL && connectionv[i] != NULL; i++) {
4a2fec
+        g_strstrip(connectionv[i]);
4a2fec
+        if (strcasecmp(connectionv[i],
4a2fec
+                       QIO_CHANNEL_WEBSOCK_CONNECTION_UPGRADE) == 0) {
4a2fec
+            upgraded = true;
4a2fec
+        }
4a2fec
+    }
4a2fec
+    g_strfreev(connectionv);
4a2fec
+    if (!upgraded) {
4a2fec
         error_setg(errp, "No connection upgrade requested '%s'", connection);
4a2fec
         goto bad_request;
4a2fec
     }
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec