From nobody Mon Apr 29 14:30:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488203366596152.9590290603321; Mon, 27 Feb 2017 05:49:26 -0800 (PST) Received: from localhost ([::1]:52929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciLg5-00070k-3i for importer@patchew.org; Mon, 27 Feb 2017 08:49:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciLSz-0003zB-Td for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciLSw-0007hB-0A for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52952) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciLSv-0007h2-Qd for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:49 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EAB85C05681A; Mon, 27 Feb 2017 13:35:49 +0000 (UTC) Received: from t460.redhat.com (ovpn-117-152.ams2.redhat.com [10.36.117.152]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RDZimc019878; Mon, 27 Feb 2017 08:35:48 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 13:35:29 +0000 Message-Id: <20170227133531.31874-2-berrange@redhat.com> In-Reply-To: <20170227133531.31874-1-berrange@redhat.com> References: <20170227133531.31874-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 27 Feb 2017 13:35:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v1 1/3] io: fix decoding when multiple websockets frames arrive at once X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The qio_channel_websock_read_wire() method will read upto 4096 bytes off the socket and then decode the websockets header and payload. The code was only decoding a single websockets frame, even if the buffered data contained multiple frames. This meant that decoding of subsequent frames was delayed until further input arrived on the socket. This backlog of delayed frames gets worse & worse over time. Symptom was that when connecting to the VNC server via the built-in websockets server, mouse/keyboard interaction would start out fine, but slowly get more & more delayed until it was unusable. Signed-off-by: Daniel P. Berrange --- io/channel-websock.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/io/channel-websock.c b/io/channel-websock.c index e47279a..a06a4a8 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -570,21 +570,24 @@ static ssize_t qio_channel_websock_read_wire(QIOChann= elWebsock *ioc, ioc->encinput.offset +=3D ret; } =20 - if (ioc->payload_remain =3D=3D 0) { - ret =3D qio_channel_websock_decode_header(ioc, errp); + while (ioc->encinput.offset !=3D 0) { + if (ioc->payload_remain =3D=3D 0) { + ret =3D qio_channel_websock_decode_header(ioc, errp); + if (ret < 0) { + return ret; + } + if (ret =3D=3D 0) { + ioc->io_eof =3D TRUE; + break; + } + } + + ret =3D qio_channel_websock_decode_payload(ioc, errp); if (ret < 0) { return ret; } - if (ret =3D=3D 0) { - return 0; - } } - - ret =3D qio_channel_websock_decode_payload(ioc, errp); - if (ret < 0) { - return ret; - } - return ret; + return 1; } =20 =20 @@ -642,9 +645,6 @@ static gboolean qio_channel_websock_flush(QIOChannel *i= oc, if (ret < 0) { goto cleanup; } - if (ret =3D=3D 0) { - wioc->io_eof =3D TRUE; - } } =20 cleanup: --=20 2.9.3 From nobody Mon Apr 29 14:30:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488203642854814.3164840256676; Mon, 27 Feb 2017 05:54:02 -0800 (PST) Received: from localhost ([::1]:52953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciLkX-0002am-Ir for importer@patchew.org; Mon, 27 Feb 2017 08:54:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciLT1-00040e-MD for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciLT0-0007jG-GA for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciLT0-0007is-2o for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:54 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C8C4C05AA4F; Mon, 27 Feb 2017 13:35:54 +0000 (UTC) Received: from t460.redhat.com (ovpn-117-152.ams2.redhat.com [10.36.117.152]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RDZimd019878; Mon, 27 Feb 2017 08:35:51 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 13:35:30 +0000 Message-Id: <20170227133531.31874-3-berrange@redhat.com> In-Reply-To: <20170227133531.31874-1-berrange@redhat.com> References: <20170227133531.31874-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 27 Feb 2017 13:35:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v1 2/3] io: ignore case in WebSocket HTTP header X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Anton Nefedov , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Anton Nefedov According to RFC7230 Section 3.2, header field name is case-insensitive. The haystack string length is limited by 4096 bytes by qio_channel_websock_handshake_read(). Further, handshake_process() dups and NULL-terminates the string so it is safe to call non length-limited functions like strcasestr(). Signed-off-by: Anton Nefedov Signed-off-by: Denis V. Lunev Signed-off-by: Daniel P. Berrange --- io/channel-websock.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/io/channel-websock.c b/io/channel-websock.c index a06a4a8..0757775 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -109,18 +109,16 @@ enum { }; =20 static char *qio_channel_websock_handshake_entry(const char *handshake, - size_t handshake_len, const char *name) { char *begin, *end, *ret =3D NULL; char *line =3D g_strdup_printf("%s%s: ", QIO_CHANNEL_WEBSOCK_HANDSHAKE_DELIM, name); - begin =3D g_strstr_len(handshake, handshake_len, line); + begin =3D strcasestr(handshake, line); if (begin !=3D NULL) { begin +=3D strlen(line); - end =3D g_strstr_len(begin, handshake_len - (begin - handshake), - QIO_CHANNEL_WEBSOCK_HANDSHAKE_DELIM); + end =3D strstr(begin, QIO_CHANNEL_WEBSOCK_HANDSHAKE_DELIM); if (end !=3D NULL) { ret =3D g_strndup(begin, end - begin); } @@ -171,12 +169,14 @@ static int qio_channel_websock_handshake_process(QIOC= hannelWebsock *ioc, Error **errp) { int ret =3D -1; + /* make it NULL-terminated */ + char *handshake =3D g_strndup(line, size); char *protocols =3D qio_channel_websock_handshake_entry( - line, size, QIO_CHANNEL_WEBSOCK_HEADER_PROTOCOL); + handshake, QIO_CHANNEL_WEBSOCK_HEADER_PROTOCOL); char *version =3D qio_channel_websock_handshake_entry( - line, size, QIO_CHANNEL_WEBSOCK_HEADER_VERSION); + handshake, QIO_CHANNEL_WEBSOCK_HEADER_VERSION); char *key =3D qio_channel_websock_handshake_entry( - line, size, QIO_CHANNEL_WEBSOCK_HEADER_KEY); + handshake, QIO_CHANNEL_WEBSOCK_HEADER_KEY); =20 if (!protocols) { error_setg(errp, "Missing websocket protocol header data"); @@ -214,6 +214,7 @@ static int qio_channel_websock_handshake_process(QIOCha= nnelWebsock *ioc, ret =3D qio_channel_websock_handshake_send_response(ioc, key, errp); =20 cleanup: + g_free(handshake); g_free(protocols); g_free(version); g_free(key); @@ -249,10 +250,12 @@ static int qio_channel_websock_handshake_read(QIOChan= nelWebsock *ioc, } } =20 - if (qio_channel_websock_handshake_process(ioc, - (char *)ioc->encinput.buffer, - ioc->encinput.offset, - errp) < 0) { + if (qio_channel_websock_handshake_process( + ioc, + (char *)ioc->encinput.buffer, + handshake_end - (char *)ioc->encinput.buffer + + strlen(QIO_CHANNEL_WEBSOCK_HANDSHAKE_END), + errp) < 0) { return -1; } =20 --=20 2.9.3 From nobody Mon Apr 29 14:30:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14882028410394.001895052962368; Mon, 27 Feb 2017 05:40:41 -0800 (PST) Received: from localhost ([::1]:52853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciLXa-0007Sk-Mp for importer@patchew.org; Mon, 27 Feb 2017 08:40:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciLT3-00042p-TZ for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciLT3-0007jy-4v for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciLT2-0007jf-Li for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:35:56 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAD4E7E9C5; Mon, 27 Feb 2017 13:35:56 +0000 (UTC) Received: from t460.redhat.com (ovpn-117-152.ams2.redhat.com [10.36.117.152]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RDZime019878; Mon, 27 Feb 2017 08:35:55 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 13:35:31 +0000 Message-Id: <20170227133531.31874-4-berrange@redhat.com> In-Reply-To: <20170227133531.31874-1-berrange@redhat.com> References: <20170227133531.31874-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 27 Feb 2017 13:35:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v1 3/3] tests: fix leaks in test-io-channel-command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau No need for strdup, fix leaks when socat is missing. Spotted by ASAN. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Daniel P. Berrange --- tests/test-io-channel-command.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test-io-channel-command.c b/tests/test-io-channel-comman= d.c index 1d1f461..46ce1ff 100644 --- a/tests/test-io-channel-command.c +++ b/tests/test-io-channel-command.c @@ -29,8 +29,8 @@ static void test_io_channel_command_fifo(bool async) #define TEST_FIFO "tests/test-io-channel-command.fifo" QIOChannel *src, *dst; QIOChannelTest *test; - char *srcfifo =3D g_strdup_printf("PIPE:%s,wronly", TEST_FIFO); - char *dstfifo =3D g_strdup_printf("PIPE:%s,rdonly", TEST_FIFO); + const char *srcfifo =3D "PIPE:" TEST_FIFO ",wronly"; + const char *dstfifo =3D "PIPE:" TEST_FIFO ",rdonly"; const char *srcargv[] =3D { "/bin/socat", "-", srcfifo, NULL, }; @@ -59,8 +59,6 @@ static void test_io_channel_command_fifo(bool async) object_unref(OBJECT(src)); object_unref(OBJECT(dst)); =20 - g_free(srcfifo); - g_free(dstfifo); unlink(TEST_FIFO); } =20 --=20 2.9.3