From patchwork Wed Feb 19 13:27:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 11391457 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 2EB2117E0 for ; Wed, 19 Feb 2020 13:28:55 +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 0570A24654 for ; Wed, 19 Feb 2020 13:28:55 +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="xUtA9V2S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0570A24654 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]:52596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4PPK-0007qI-7m for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Feb 2020 08:28:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38979) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4POX-0006WD-Uj for qemu-devel@nongnu.org; Wed, 19 Feb 2020 08:28:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4POW-0004vb-TD for qemu-devel@nongnu.org; Wed, 19 Feb 2020 08:28:05 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:33940) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4POU-0004uE-Lg; Wed, 19 Feb 2020 08:28:02 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01JDS1tJ016061; Wed, 19 Feb 2020 13:28:01 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=7WygD6+kjiCue9xK0ryDh1l6dlgkKsAMTazxsr2Kvqk=; b=xUtA9V2SLFlIYdr+moO2/Bmcv9pm7o0JGRLYm5OWJ6hKh0pBls2N1Ty5V22CDtmfsHa0 Lvu0U/AV9bO+vFQagPe8rxbeejFqFSVxcHqEL9LyfhGpvhW4BTGufO387JMLqqlyND/7 Q8dp6mVQbiy3uIvBKPhpoJG91HbMy9BZ+gcgVe4KpuNdB7TXfu7eAADCQ/ilc12nrG8v SW2Tebofz4PV3MddDUHXNPzuk6efi068LRthQBZOVjYodyy9K7BxJkYjklItGF1yTAZD iwIiKj7pC7GBxxItUr41PXUtBErZ3U/ZKGuNLUBmB2zLgs9fEKIoPbwvcjOpSUw40f6W 9Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2y8ud12y2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Feb 2020 13:27:55 +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 01JDRsv3175877; Wed, 19 Feb 2020 13:27:54 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2y8ud5eab2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Feb 2020 13:27:54 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01JDRnuQ030143; Wed, 19 Feb 2020 13:27:49 GMT Received: from disaster-area.hh.sledj.net (/81.149.164.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 19 Feb 2020 05:27:48 -0800 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id c325e49d; Wed, 19 Feb 2020 13:27:45 +0000 (UTC) From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH 1/2] block/curl: HTTP header fields allow whitespace around values Date: Wed, 19 Feb 2020 13:27:43 +0000 Message-Id: <20200219132745.315381-2-david.edmondson@oracle.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200219132745.315381-1-david.edmondson@oracle.com> References: <20200219132745.315381-1-david.edmondson@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9535 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 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-2002190103 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9535 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 malwarescore=0 suspectscore=1 bulkscore=0 spamscore=0 priorityscore=1501 phishscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190103 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 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..0cf99a4b31b8 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 && 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 && isspace(*p)) { + p++; + } + + if (p == end || !*p) { + s->accept_range = true; + } + } } return realsize; From patchwork Wed Feb 19 13:27:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 11391459 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 2CCE6159A for ; Wed, 19 Feb 2020 13:29:04 +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 039E124670 for ; Wed, 19 Feb 2020 13:29:03 +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="wmZ60gmx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 039E124670 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]:52600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4PPT-0008DG-57 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Feb 2020 08:29:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38992) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4POZ-0006Yh-Hk for qemu-devel@nongnu.org; Wed, 19 Feb 2020 08:28:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4POY-0004wB-Ff for qemu-devel@nongnu.org; Wed, 19 Feb 2020 08:28:07 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:48354) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4POS-0004ou-IA; Wed, 19 Feb 2020 08:28:00 -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 01JDJE2h097137; Wed, 19 Feb 2020 13:27:51 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=5ocdY08IEE1IEW6dKvI5l6OPdlNgoONwqxta5oLdrSQ=; b=wmZ60gmx1TZ/J2mV0bnc4pdtA0QWQDIQNJo4mcBkEz8IkyBfm4PqusXFcrThusHIBCts yr6ArVF5xtWWS7+a7YcCT4Zzky+263tLkYAgUN4qLDKrazzmUymQ9cngiBeRXlCmMs1Q st+wgipeD1t5LZWzD0SAi2SHxG8J9h79dQEI2Tq90xzN2r9/o6Jql+0RS8PRj1hK/+9i IJa7mdJj4bbzi9uVw1TfhBMggq7D53IqMGizgNKxZOSYnHyfBihYJHG9JzeA0ywCkibx CQbu3+wpqnp599YRocTpD6e4CS8QqkLpE/eYWA8LzoR/JyO8iSxCNr8rQgfkNVuvA1Du Pg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2y8udkaxp2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Feb 2020 13:27:51 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01JDIp0Z113257; Wed, 19 Feb 2020 13:27:50 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2y8udageyw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Feb 2020 13:27:50 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01JDRoQK005652; Wed, 19 Feb 2020 13:27:50 GMT Received: from disaster-area.hh.sledj.net (/81.149.164.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 19 Feb 2020 05:27:49 -0800 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 44951f96; Wed, 19 Feb 2020 13:27:45 +0000 (UTC) From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH 2/2] block/curl: HTTP header field names are case insensitive Date: Wed, 19 Feb 2020 13:27:44 +0000 Message-Id: <20200219132745.315381-3-david.edmondson@oracle.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200219132745.315381-1-david.edmondson@oracle.com> References: <20200219132745.315381-1-david.edmondson@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9535 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=1 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190102 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9535 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=1011 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-2002190102 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 0cf99a4b31b8..4256659cd85b 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) { + && strncasecmp(header, accept_ranges, strlen(accept_ranges)) == 0) { char *p = strchr(header, ':') + 1;