From nobody Mon Feb 9 09:22:34 2026 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.zohomail.com; dkim=fail; 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 1504892943627274.79993755765395; Fri, 8 Sep 2017 10:49:03 -0700 (PDT) Received: from localhost ([::1]:46723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqNOo-0000yh-Ju for importer@patchew.org; Fri, 08 Sep 2017 13:49:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqNFQ-0000KF-4k for qemu-devel@nongnu.org; Fri, 08 Sep 2017 13:39:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dqNFO-0008Jy-MX for qemu-devel@nongnu.org; Fri, 08 Sep 2017 13:39:20 -0400 Received: from mail-pf0-x236.google.com ([2607:f8b0:400e:c00::236]:36684) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dqNFO-0008JU-H7 for qemu-devel@nongnu.org; Fri, 08 Sep 2017 13:39:18 -0400 Received: by mail-pf0-x236.google.com with SMTP id e199so5536540pfh.3 for ; Fri, 08 Sep 2017 10:39:18 -0700 (PDT) Received: from servo.cypherpath.com (68-113-0-218.static.knwc.wa.charter.com. [68.113.0.218]) by smtp.gmail.com with ESMTPSA id c30sm4556833pgn.33.2017.09.08.10.39.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 10:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cypherpath.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=r14jgAiyO+0nsjjc9Wc+WdEfYoQD51qE/EukutcUoUA=; b=Zvplk6+k9EOww8Q6SdgR5N+NCgWhCZbNHVHmlqAHPVeJBtYfvzAuKf2T8HzQ/4/7WE KNJ5CwkDeJZrY5S8/uvwnqXjEBD50e07PGl01kvEFSFsylwFzzuAIYBJQPPG4Zc0hm5B gg4vBOPABSTpYhl89fe/z/Om0Iw+VhDA7FKtU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=r14jgAiyO+0nsjjc9Wc+WdEfYoQD51qE/EukutcUoUA=; b=sW6DJWtvVUDuJNCu5ITu5qOUI+St6LoAzPwQ4P/UB1lQzXlvxNdyZduaBtoh092Qon /o4i2275dt3MGKEPs1+Z+aLMf6KkQ0AqXkp63YklJCSPtOythaeZmageoKP7FNNbmhgZ kHtrjfQcYO+Q6BD5O5O4z7Q4aWnrg40O72IPSmm4+Ab09RJ8cYAAvoF1XKSwpNYycl48 m8GxQcf7kPLLbKyS81w8EUY9+FlVtdeH/vckcMrYL7VkvPnKFTIQA0IikCsBRhnghWym KnrCIekejz/btoiRACUE8EIhhSktEoKW2+tB8XJFQ908H2lmf94j6dto1rY+snKlChJz zS+Q== X-Gm-Message-State: AHPjjUiIwmaZ+B6R0uet3u+boIcBdYWgtAFo0ns7770PX/Xu1eXmD8Hb kfLbP3SceGJyNoSTve+A7C9Qw8zU23eXOgh74E0c38JMt/YapMxo3nP3HKnsENFnjHRQg8dJxyl VwC1b MIME-Version: 1.0 X-Google-Smtp-Source: ADKCNb4UR7ownPTAgZq6XlWdFqoJlmeZQwMlCxam8aNvr6MgyhbmdyVE0FGACjOgNof/ZlpNIV9NJw== X-Received: by 10.98.81.4 with SMTP id f4mr3860015pfb.275.1504892357486; Fri, 08 Sep 2017 10:39:17 -0700 (PDT) From: Brandon Carpenter 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> References: <20170908173801.15205-1-brandon.carpenter@cypherpath.com> In-Reply-To: <20170724184217.21381-1-brandon.carpenter@cypherpath.com> References: <20170724184217.21381-1-brandon.carpenter@cypherpath.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: brandon.carpenter@cypherpath.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some browsers send pings/pongs with no payload, so allow empty payloads instead of closing the connection. Signed-off-by: Brandon Carpenter --- io/channel-websock.c | 62 +++++++++++++++++++++++++-----------------------= ---- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/io/channel-websock.c b/io/channel-websock.c index ced24135ec..3183aeff77 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -603,44 +603,42 @@ static int qio_channel_websock_decode_payload(QIOChan= nelWebsock *ioc, Error **errp) { size_t i; - size_t payload_len; + size_t payload_len =3D 0; uint32_t *payload32; =20 - if (!ioc->payload_remain) { - error_setg(errp, - "Decoding payload but no bytes of payload remain"); - return -1; - } - - /* If we aren't at the end of the payload, then drop - * off the last bytes, so we're always multiple of 4 - * for purpose of unmasking, except at end of payload - */ - if (ioc->encinput.offset < ioc->payload_remain) { - payload_len =3D ioc->encinput.offset - (ioc->encinput.offset % 4); - } else { - payload_len =3D ioc->payload_remain; - } - if (payload_len =3D=3D 0) { - return QIO_CHANNEL_ERR_BLOCK; - } + if (ioc->payload_remain) { + /* If we aren't at the end of the payload, then drop + * off the last bytes, so we're always multiple of 4 + * for purpose of unmasking, except at end of payload + */ + if (ioc->encinput.offset < ioc->payload_remain) { + payload_len =3D ioc->encinput.offset - (ioc->encinput.offset %= 4); + } else { + payload_len =3D ioc->payload_remain; + } + if (payload_len =3D=3D 0) { + return QIO_CHANNEL_ERR_BLOCK; + } =20 - ioc->payload_remain -=3D payload_len; + ioc->payload_remain -=3D payload_len; =20 - /* unmask frame */ - /* process 1 frame (32 bit op) */ - payload32 =3D (uint32_t *)ioc->encinput.buffer; - for (i =3D 0; i < payload_len / 4; i++) { - payload32[i] ^=3D ioc->mask.u; - } - /* process the remaining bytes (if any) */ - for (i *=3D 4; i < payload_len; i++) { - ioc->encinput.buffer[i] ^=3D ioc->mask.c[i % 4]; + /* unmask frame */ + /* process 1 frame (32 bit op) */ + payload32 =3D (uint32_t *)ioc->encinput.buffer; + for (i =3D 0; i < payload_len / 4; i++) { + payload32[i] ^=3D ioc->mask.u; + } + /* process the remaining bytes (if any) */ + for (i *=3D 4; i < payload_len; i++) { + ioc->encinput.buffer[i] ^=3D ioc->mask.c[i % 4]; + } } =20 - buffer_reserve(&ioc->rawinput, payload_len); - buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len); - buffer_advance(&ioc->encinput, payload_len); + if (payload_len) { + buffer_reserve(&ioc->rawinput, payload_len); + buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len); + buffer_advance(&ioc->encinput, payload_len); + } return 0; } =20 --=20 2.14.1 --=20 CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is=20 for the sole use of the intended recipient(s) and may contain proprietary,=20 confidential or privileged information or otherwise be protected by law.=20 Any unauthorized review, use, disclosure or distribution is prohibited. If=20 you are not the intended recipient, please notify the sender and destroy=20 all copies and the original message.