From: "Denis V. Lunev" <den@openvz.org>
To: qemu-devel@nongnu.org
Cc: den@openvz.org, "Daniel P . Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH 1/1] websock: treat upgrade header in case insensitive way
Date: Fri, 29 Sep 2017 17:56:29 +0300 [thread overview]
Message-ID: <20170929145629.14766-1-den@openvz.org> (raw)
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 <den@openvz.org>
CC: Daniel P. Berrange <berrange@redhat.com>
---
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
next reply other threads:[~2017-09-29 14:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-29 14:56 Denis V. Lunev [this message]
2017-09-29 16:19 ` [Qemu-devel] [PATCH 1/1] websock: treat upgrade header in case insensitive way Daniel P. Berrange
2017-09-29 17:07 ` Denis V. Lunev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170929145629.14766-1-den@openvz.org \
--to=den@openvz.org \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).