{"id":811749,"url":"http://patchwork.ozlabs.org/api/patches/811749/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170908173801.15205-5-brandon.carpenter@cypherpath.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170908173801.15205-5-brandon.carpenter@cypherpath.com>","list_archive_url":null,"date":"2017-09-08T17:37:59","name":"[v2,4/6] io: Allow empty websocket payload","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c635e4663ddc0e09e6a58b9410e003be0b277fcd","submitter":{"id":72031,"url":"http://patchwork.ozlabs.org/api/people/72031/?format=json","name":"Brandon Carpenter","email":"brandon.carpenter@cypherpath.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170908173801.15205-5-brandon.carpenter@cypherpath.com/mbox/","series":[{"id":2262,"url":"http://patchwork.ozlabs.org/api/series/2262/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2262","date":"2017-09-08T17:37:56","name":"Update websocket code to more fully support the RFC","version":2,"mbox":"http://patchwork.ozlabs.org/series/2262/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811749/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811749/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=cypherpath.com header.i=@cypherpath.com\n\theader.b=\"Zvplk6+k\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xplCf6X0Mz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  9 Sep 2017 03:47:55 +1000 (AEST)","from localhost ([::1]:46717 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dqNNg-0007wc-K8\n\tfor incoming@patchwork.ozlabs.org; Fri, 08 Sep 2017 13:47:52 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:40093)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1dqNFQ-0000KF-4k\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 13:39:21 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1dqNFO-0008Jy-MX\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 13:39:20 -0400","from mail-pf0-x236.google.com ([2607:f8b0:400e:c00::236]:36684)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1dqNFO-0008JU-H7\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 13:39:18 -0400","by mail-pf0-x236.google.com with SMTP id e199so5536540pfh.3\n\tfor <qemu-devel@nongnu.org>; Fri, 08 Sep 2017 10:39:18 -0700 (PDT)","from servo.cypherpath.com (68-113-0-218.static.knwc.wa.charter.com.\n\t[68.113.0.218]) by smtp.gmail.com with ESMTPSA id\n\tc30sm4556833pgn.33.2017.09.08.10.39.16\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tFri, 08 Sep 2017 10:39:16 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=cypherpath.com; s=google;\n\th=mime-version:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:in-reply-to:references;\n\tbh=r14jgAiyO+0nsjjc9Wc+WdEfYoQD51qE/EukutcUoUA=;\n\tb=Zvplk6+k9EOww8Q6SdgR5N+NCgWhCZbNHVHmlqAHPVeJBtYfvzAuKf2T8HzQ/4/7WE\n\tKNJ5CwkDeJZrY5S8/uvwnqXjEBD50e07PGl01kvEFSFsylwFzzuAIYBJQPPG4Zc0hm5B\n\tgg4vBOPABSTpYhl89fe/z/Om0Iw+VhDA7FKtU=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id\n\t:in-reply-to:references:in-reply-to:references;\n\tbh=r14jgAiyO+0nsjjc9Wc+WdEfYoQD51qE/EukutcUoUA=;\n\tb=sW6DJWtvVUDuJNCu5ITu5qOUI+St6LoAzPwQ4P/UB1lQzXlvxNdyZduaBtoh092Qon\n\t/o4i2275dt3MGKEPs1+Z+aLMf6KkQ0AqXkp63YklJCSPtOythaeZmageoKP7FNNbmhgZ\n\tkHtrjfQcYO+Q6BD5O5O4z7Q4aWnrg40O72IPSmm4+Ab09RJ8cYAAvoF1XKSwpNYycl48\n\tm8GxQcf7kPLLbKyS81w8EUY9+FlVtdeH/vckcMrYL7VkvPnKFTIQA0IikCsBRhnghWym\n\tKnrCIekejz/btoiRACUE8EIhhSktEoKW2+tB8XJFQ908H2lmf94j6dto1rY+snKlChJz\n\tzS+Q==","X-Gm-Message-State":"AHPjjUiIwmaZ+B6R0uet3u+boIcBdYWgtAFo0ns7770PX/Xu1eXmD8Hb\n\tkfLbP3SceGJyNoSTve+A7C9Qw8zU23eXOgh74E0c38JMt/YapMxo3nP3HKnsENFnjHRQg8dJxyl\n\tVwC1b","MIME-Version":"1.0","X-Google-Smtp-Source":"ADKCNb4UR7ownPTAgZq6XlWdFqoJlmeZQwMlCxam8aNvr6MgyhbmdyVE0FGACjOgNof/ZlpNIV9NJw==","X-Received":"by 10.98.81.4 with SMTP id f4mr3860015pfb.275.1504892357486;\n\tFri, 08 Sep 2017 10:39:17 -0700 (PDT)","From":"Brandon Carpenter <brandon.carpenter@cypherpath.com>","To":"qemu-devel@nongnu.org","Date":"Fri,  8 Sep 2017 10:37:59 -0700","Message-Id":"<20170908173801.15205-5-brandon.carpenter@cypherpath.com>","X-Mailer":"git-send-email 2.14.1","In-Reply-To":["<20170908173801.15205-1-brandon.carpenter@cypherpath.com>","<20170724184217.21381-1-brandon.carpenter@cypherpath.com>"],"References":["<20170908173801.15205-1-brandon.carpenter@cypherpath.com>","<20170724184217.21381-1-brandon.carpenter@cypherpath.com>"],"Content-Type":"text/plain; charset=\"US-ASCII\"","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:400e:c00::236","Subject":"[Qemu-devel] [PATCH v2 4/6] io: Allow empty websocket payload","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"brandon.carpenter@cypherpath.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"Some browsers send pings/pongs with no payload, so allow empty payloads\ninstead of closing the connection.\n\nSigned-off-by: Brandon Carpenter <brandon.carpenter@cypherpath.com>\n---\n io/channel-websock.c | 62 +++++++++++++++++++++++++---------------------------\n 1 file changed, 30 insertions(+), 32 deletions(-)","diff":"diff --git a/io/channel-websock.c b/io/channel-websock.c\nindex ced24135ec..3183aeff77 100644\n--- a/io/channel-websock.c\n+++ b/io/channel-websock.c\n@@ -603,44 +603,42 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,\n                                               Error **errp)\n {\n     size_t i;\n-    size_t payload_len;\n+    size_t payload_len = 0;\n     uint32_t *payload32;\n \n-    if (!ioc->payload_remain) {\n-        error_setg(errp,\n-                   \"Decoding payload but no bytes of payload remain\");\n-        return -1;\n-    }\n-\n-    /* If we aren't at the end of the payload, then drop\n-     * off the last bytes, so we're always multiple of 4\n-     * for purpose of unmasking, except at end of payload\n-     */\n-    if (ioc->encinput.offset < ioc->payload_remain) {\n-        payload_len = ioc->encinput.offset - (ioc->encinput.offset % 4);\n-    } else {\n-        payload_len = ioc->payload_remain;\n-    }\n-    if (payload_len == 0) {\n-        return QIO_CHANNEL_ERR_BLOCK;\n-    }\n+    if (ioc->payload_remain) {\n+        /* If we aren't at the end of the payload, then drop\n+         * off the last bytes, so we're always multiple of 4\n+         * for purpose of unmasking, except at end of payload\n+         */\n+        if (ioc->encinput.offset < ioc->payload_remain) {\n+            payload_len = ioc->encinput.offset - (ioc->encinput.offset % 4);\n+        } else {\n+            payload_len = ioc->payload_remain;\n+        }\n+        if (payload_len == 0) {\n+            return QIO_CHANNEL_ERR_BLOCK;\n+        }\n \n-    ioc->payload_remain -= payload_len;\n+        ioc->payload_remain -= payload_len;\n \n-    /* unmask frame */\n-    /* process 1 frame (32 bit op) */\n-    payload32 = (uint32_t *)ioc->encinput.buffer;\n-    for (i = 0; i < payload_len / 4; i++) {\n-        payload32[i] ^= ioc->mask.u;\n-    }\n-    /* process the remaining bytes (if any) */\n-    for (i *= 4; i < payload_len; i++) {\n-        ioc->encinput.buffer[i] ^= ioc->mask.c[i % 4];\n+        /* unmask frame */\n+        /* process 1 frame (32 bit op) */\n+        payload32 = (uint32_t *)ioc->encinput.buffer;\n+        for (i = 0; i < payload_len / 4; i++) {\n+            payload32[i] ^= ioc->mask.u;\n+        }\n+        /* process the remaining bytes (if any) */\n+        for (i *= 4; i < payload_len; i++) {\n+            ioc->encinput.buffer[i] ^= ioc->mask.c[i % 4];\n+        }\n     }\n \n-    buffer_reserve(&ioc->rawinput, payload_len);\n-    buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len);\n-    buffer_advance(&ioc->encinput, payload_len);\n+    if (payload_len) {\n+        buffer_reserve(&ioc->rawinput, payload_len);\n+        buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len);\n+        buffer_advance(&ioc->encinput, payload_len);\n+    }\n     return 0;\n }\n \n","prefixes":["v2","4/6"]}