From patchwork Fri Feb 21 16:32:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 11396871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A9C1109A for ; Fri, 21 Feb 2020 16:35:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1126920679 for ; Fri, 21 Feb 2020 16:35:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="pUD9bgOK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1126920679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:32866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5BHI-0005M6-8P for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Feb 2020 11:35:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49438) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5BER-00013g-IS for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:32:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5BEQ-0000NJ-Hx for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:32:51 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:35766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j5BEN-0000LA-LS; Fri, 21 Feb 2020 11:32:47 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01LGV5bH024253; Fri, 21 Feb 2020 16:32:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=iBNQeoHxQwvpeGKNBw3AigaYz1rA0uTaMhD0FMSxPgc=; b=pUD9bgOKifQOoVZmcncUcje5RrJYt8BHUT/MCXqc39xboQPh+wrXpx2SQPxBSAl3qMiy VzNgIh020iwyhMoy0on5BUvtYUhT3YPobBhoofSPAJus8MRqSlbIYFEk0RZ/ROHhLwM6 JpyX69C1akN/jYNRnrlKSUXwCNuGYr5O9NSNaHRxO/YvxqLDxh2lBD5tE8KJ/mcQAXi8 6HwiV2FGRElDnD/vVsOLgxCraap4IXB0fW7D3fg6SjCutiGIi3Y2zyR01rvjP7fCZI9c Piz/eHixEx2eIfByL1VRqos0NjOgpK6MBAvD6jfZyBXmZjQen6XsZQZllTRJjilcUx0+ aA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2y8uddhm1n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Feb 2020 16:32:45 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01LGVsXX124539; Fri, 21 Feb 2020 16:32:44 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2y8udnskst-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Feb 2020 16:32:44 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01LGWhpL019996; Fri, 21 Feb 2020 16:32:43 GMT Received: from disaster-area.hh.sledj.net (/81.187.26.238) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Feb 2020 08:32:42 -0800 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id a95ab626; Fri, 21 Feb 2020 16:32:39 +0000 (UTC) From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] block/curl: HTTP header fields allow whitespace around values Date: Fri, 21 Feb 2020 16:32:37 +0000 Message-Id: <20200221163238.60688-2-david.edmondson@oracle.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200221163238.60688-1-david.edmondson@oracle.com> References: <20200221163238.60688-1-david.edmondson@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9538 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=996 phishscore=0 suspectscore=1 mlxscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002210124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9538 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 suspectscore=1 priorityscore=1501 bulkscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002210123 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , David Edmondson , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" RFC 7230 section 3.2 indicates that whitespace is permitted between the field name and field value and after the field value. Signed-off-by: David Edmondson --- block/curl.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/block/curl.c b/block/curl.c index f86299378e38..f9ffb7f4e2bf 100644 --- a/block/curl.c +++ b/block/curl.c @@ -214,11 +214,34 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque) { BDRVCURLState *s = opaque; size_t realsize = size * nmemb; - const char *accept_line = "Accept-Ranges: bytes"; + const char *header = (char *)ptr; + const char *end = header + realsize; + const char *accept_ranges = "Accept-Ranges:"; + const char *bytes = "bytes"; - if (realsize >= strlen(accept_line) - && strncmp((char *)ptr, accept_line, strlen(accept_line)) == 0) { - s->accept_range = true; + if (realsize >= strlen(accept_ranges) + && strncmp(header, accept_ranges, strlen(accept_ranges)) == 0) { + + char *p = strchr(header, ':') + 1; + + /* Skip whitespace between the header name and value. */ + while (p < end && *p && g_ascii_isspace(*p)) { + p++; + } + + if (end - p >= strlen(bytes) + && strncmp(p, bytes, strlen(bytes)) == 0) { + + /* Check that there is nothing but whitespace after the value. */ + p += strlen(bytes); + while (p < end && *p && g_ascii_isspace(*p)) { + p++; + } + + if (p == end || !*p) { + s->accept_range = true; + } + } } return realsize; From patchwork Fri Feb 21 16:32:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 11396863 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F18E4109A for ; Fri, 21 Feb 2020 16:33:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 86859208E4 for ; Fri, 21 Feb 2020 16:33:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="XsQbS9do" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86859208E4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:32814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5BFI-0002ey-B5 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Feb 2020 11:33:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49435) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5BER-00013X-C2 for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:32:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5BEQ-0000ND-CQ for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:32:51 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:45414) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j5BEN-0000LM-Lo; Fri, 21 Feb 2020 11:32:47 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01LGVe7Q104073; Fri, 21 Feb 2020 16:32:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=dMx0ZLYFM2GPQghj/Kt4dIRM5hEYlRsBsdw8Mdx6+Io=; b=XsQbS9dowjIo17DY2krbmseQCzb6AvOeBgq/XKj9Po5e/7x8ftNmymllUMAKC0L406xd lNaYioeVHo00RiLAvqxglzm0slRANeCyW1vcdicaI2ug79/kx7p336YPhFlOTLETtmV/ puk8sY7TGyR2kV8QAXSkQFVlqG241IMvDSGdR2sEKU7V5Wecv+0zYu/ZJVqwxESQ+mMK 81VB7F4+BWRQQidt2jlbWYdB0z3OFot3q1ZD3GyLnNnj8Az4mAZ1Sw9ntinJEDeuqAtH Z0GShLdk2B1SeSJ1eNJlh2YUOOu/URili0QEgGErfYFhat4uJIymKyJFhIgH9f7cRRqG WA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2y8udkskbh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Feb 2020 16:32:45 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01LGVhn8086015; Fri, 21 Feb 2020 16:32:44 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2y8ud710wb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Feb 2020 16:32:44 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01LGWi7Q019999; Fri, 21 Feb 2020 16:32:44 GMT Received: from disaster-area.hh.sledj.net (/81.187.26.238) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Feb 2020 08:32:43 -0800 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 42591949; Fri, 21 Feb 2020 16:32:39 +0000 (UTC) From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] block/curl: HTTP header field names are case insensitive Date: Fri, 21 Feb 2020 16:32:38 +0000 Message-Id: <20200221163238.60688-3-david.edmondson@oracle.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200221163238.60688-1-david.edmondson@oracle.com> References: <20200221163238.60688-1-david.edmondson@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9538 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxlogscore=999 suspectscore=1 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002210124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9538 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 suspectscore=1 spamscore=0 priorityscore=1501 adultscore=0 mlxscore=0 clxscore=1015 malwarescore=0 mlxlogscore=999 phishscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002210123 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , David Edmondson , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" RFC 7230 section 3.2 indicates that HTTP header field names are case insensitive. Signed-off-by: David Edmondson --- block/curl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/curl.c b/block/curl.c index f9ffb7f4e2bf..1421e8fb9815 100644 --- a/block/curl.c +++ b/block/curl.c @@ -216,11 +216,11 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque) size_t realsize = size * nmemb; const char *header = (char *)ptr; const char *end = header + realsize; - const char *accept_ranges = "Accept-Ranges:"; + const char *accept_ranges = "accept-ranges:"; const char *bytes = "bytes"; if (realsize >= strlen(accept_ranges) - && strncmp(header, accept_ranges, strlen(accept_ranges)) == 0) { + && g_ascii_strncasecmp(header, accept_ranges, strlen(accept_ranges)) == 0) { char *p = strchr(header, ':') + 1;