qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/1] websock: treat upgrade header in case insensiti


From: Denis V. Lunev
Subject: [Qemu-devel] [PATCH 1/1] websock: treat upgrade header in case insensitive way
Date: Fri, 29 Sep 2017 17:56:29 +0300

According to rfc6455 section 4.2.1. Reading the Client's Opening Handshake
  An |Upgrade| header field containing the value "websocket",
  treated as an ASCII case-insensitive value.

Current implementation in QEMU accepts this header in lower-case only,
which is revealed to have broken some real-life clients. We need to
convert the value of this header to lower case before comparison.
Unfortunately we can not do that for all headers. Only this specific one
should be converted this way.

Signed-off-by: Denis V. Lunev <address@hidden>
CC: Daniel P. Berrange <address@hidden>
---
 io/channel-websock.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/io/channel-websock.c b/io/channel-websock.c
index 5a3badbec2..d925f0a275 100644
--- a/io/channel-websock.c
+++ b/io/channel-websock.c
@@ -123,6 +123,14 @@ enum {
     QIO_CHANNEL_WEBSOCK_OPCODE_PONG = 0xA
 };
 
+static void str_tolower(char *buffer)
+{
+    char *tmp;
+    for (tmp = buffer; *tmp; tmp++) {
+        *tmp = g_ascii_tolower(*tmp);
+    }
+}
+
 static size_t
 qio_channel_websock_extract_headers(char *buffer,
                                     QIOChannelWebsockHTTPHeader *hdrs,
@@ -221,9 +229,7 @@ qio_channel_websock_extract_headers(char *buffer,
         hdr->value = sep;
 
         /* Canonicalize header name for easier identification later */
-        for (tmp = hdr->name; *tmp; tmp++) {
-            *tmp = g_ascii_tolower(*tmp);
-        }
+        str_tolower(hdr->name);
 
         if (nl) {
             buffer = nl + strlen(QIO_CHANNEL_WEBSOCK_HANDSHAKE_DELIM);
@@ -233,7 +239,7 @@ qio_channel_websock_extract_headers(char *buffer,
     return nhdrs;
 }
 
-static const char *
+static char *
 qio_channel_websock_find_header(QIOChannelWebsockHTTPHeader *hdrs,
                                 size_t nhdrs,
                                 const char *name)
@@ -291,7 +297,7 @@ static int 
qio_channel_websock_handshake_process(QIOChannelWebsock *ioc,
 {
     QIOChannelWebsockHTTPHeader hdrs[32];
     size_t nhdrs = G_N_ELEMENTS(hdrs);
-    const char *protocols = NULL, *version = NULL, *key = NULL,
+    char *protocols = NULL, *version = NULL, *key = NULL,
         *host = NULL, *connection = NULL, *upgrade = NULL;
 
     nhdrs = qio_channel_websock_extract_headers(buffer, hdrs, nhdrs, errp);
@@ -340,6 +346,7 @@ static int 
qio_channel_websock_handshake_process(QIOChannelWebsock *ioc,
         error_setg(errp, "Missing websocket upgrade header data");
         return -1;
     }
+    str_tolower(upgrade);
 
     if (!g_strrstr(protocols, QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY)) {
         error_setg(errp, "No '%s' protocol is supported by client '%s'",
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]