From nobody Sun Feb 8 23:05:12 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 1504893016152746.4618057092067; Fri, 8 Sep 2017 10:50:16 -0700 (PDT) Received: from localhost ([::1]:46727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqNPz-0001yK-7C for importer@patchew.org; Fri, 08 Sep 2017 13:50:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqNFQ-0000KE-4X 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 1dqNFN-0008JN-Uw for qemu-devel@nongnu.org; Fri, 08 Sep 2017 13:39:20 -0400 Received: from mail-pg0-x22b.google.com ([2607:f8b0:400e:c05::22b]:35052) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dqNFN-0008J1-Ot for qemu-devel@nongnu.org; Fri, 08 Sep 2017 13:39:17 -0400 Received: by mail-pg0-x22b.google.com with SMTP id 188so5918619pgb.2 for ; Fri, 08 Sep 2017 10:39:17 -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.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 10:39:15 -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=ynGU1w3AUPeqi+qwRQdEmX20o6+XJQrZapNWIyIuUgE=; b=c1tdrJVKAqrUPv1C8T71iD7LAXeuo+3nRECtLiB19TlWNUhIdGLGHnYCXK7gzHZ3jB lzi4aqU6nyWVnxsncnyh/dhMzpTKKc6R7XCPgnrClLFATO96opsKNuDMPlOKSUGNri8N xpfZ7CUjejX5rzPNsX2wMy7CcvHLuizcT517U= 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=ynGU1w3AUPeqi+qwRQdEmX20o6+XJQrZapNWIyIuUgE=; b=Tg7nj4Rum/FL3fZW4LNxvWyV7HC9tSAaeZXAfVqv4PhLTC7IrhZkw4DvqWiFcvFoSq CCARhj/SU4eZrpJCYRMSsGnmgoydKkHDjGXnqzfp4YiAuzh3GL1eTz8W181+/UtSO14r LO26HZTwkD7+gx81TefgqI/YVFn3IZYcFir/BwjyYvozkGXB6bqkdaXJvTjVp5WBEwtw ucVV5LHOPyRGnlnbTNI1ieOARrl5zZLvw7kcE9x2qPTD84ZAla87SGOZEhaOfJCBFE0i 0S08v6vHj837XdvdodH1tzO8B2eUWgLtWoEin04h6PNZQbhW2DuLfZOKOo4aUxqX1KO3 RT4A== X-Gm-Message-State: AHPjjUheiRXekiH8tgVmj9NXUn/cLHAUSbecGywhcSLN9ukyZPdy2nOf aY9lXhZlCgMMcW5AvrEFJmbDGQDtdAD7RQdWM9KwgiitXRZ+AspJeNkX/9fzOEO/vfzT4Y0SOcT zgKgj MIME-Version: 1.0 X-Google-Smtp-Source: ADKCNb4AcdqioabXSeoDEzxCr9MHAVAFhEoEJze+oWToDBbfe+L/1DdwAkegZBirNDeZOQ/C9LD1Vg== X-Received: by 10.98.64.138 with SMTP id f10mr3899132pfd.246.1504892356611; Fri, 08 Sep 2017 10:39:16 -0700 (PDT) From: Brandon Carpenter To: qemu-devel@nongnu.org Date: Fri, 8 Sep 2017 10:37:58 -0700 Message-Id: <20170908173801.15205-4-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:c05::22b Subject: [Qemu-devel] [PATCH v2 3/6] io: Add support for fragmented websocket binary frames 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" Allows fragmented binary frames by saving the previous opcode. Handles the case where an intermediary (i.e., web proxy) fragments frames originally sent unfragmented by the client. Signed-off-by: Brandon Carpenter --- include/io/channel-websock.h | 1 + io/channel-websock.c | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/io/channel-websock.h b/include/io/channel-websock.h index 3c9ff84727..7c896557c5 100644 --- a/include/io/channel-websock.h +++ b/include/io/channel-websock.h @@ -65,6 +65,7 @@ struct QIOChannelWebsock { guint io_tag; Error *io_err; gboolean io_eof; + uint8_t opcode; }; =20 /** diff --git a/io/channel-websock.c b/io/channel-websock.c index 185bd31be5..ced24135ec 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -542,28 +542,38 @@ static int qio_channel_websock_decode_header(QIOChann= elWebsock *ioc, has_mask =3D header->b1 & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_HAS_MASK; payload_len =3D header->b1 & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_PAYLOAD_= LEN; =20 + /* Save or restore opcode. */ + if (opcode) { + ioc->opcode =3D opcode; + } else { + opcode =3D ioc->opcode; + } + if (opcode =3D=3D QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE) { /* disconnect */ return 0; } =20 /* Websocket frame sanity check: - * * Websocket fragmentation is not supported. - * * All websockets frames sent by a client have to be masked. + * * Fragmentation is only supported for binary frames. + * * All frames sent by a client MUST be masked. * * Only binary encoding is supported. */ if (!fin) { - error_setg(errp, "websocket fragmentation is not supported"); - return -1; + if (opcode !=3D QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) { + error_setg(errp, "only binary websocket frames may be fragment= ed"); + return -1; + } + } else { + if (opcode !=3D QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) { + error_setg(errp, "only binary websocket frames are supported"); + return -1; + } } if (!has_mask) { error_setg(errp, "client websocket frames must be masked"); return -1; } - if (opcode !=3D QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) { - error_setg(errp, "only binary websocket frames are supported"); - return -1; - } =20 if (payload_len < QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_16_BIT) { ioc->payload_remain =3D payload_len; --=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.