thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-curl-HTTP-header-fields-allow-whitespace-aroun.patch

902636
From e5ac775de83d3d22f13c74ab198780b8b579f684 Mon Sep 17 00:00:00 2001
902636
From: Richard Jones <rjones@redhat.com>
902636
Date: Thu, 28 May 2020 14:27:36 +0100
902636
Subject: [PATCH 02/26] block/curl: HTTP header fields allow whitespace around
902636
 values
902636
902636
RH-Author: Richard Jones <rjones@redhat.com>
902636
Message-id: <20200528142737.17318-2-rjones@redhat.com>
902636
Patchwork-id: 96894
902636
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 1/2] block/curl: HTTP header fields allow whitespace around values
902636
Bugzilla: 1841038
902636
RH-Acked-by: Eric Blake <eblake@redhat.com>
902636
RH-Acked-by: Max Reitz <mreitz@redhat.com>
902636
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
902636
902636
From: David Edmondson <david.edmondson@oracle.com>
902636
902636
RFC 7230 section 3.2 indicates that whitespace is permitted between
902636
the field name and field value and after the field value.
902636
902636
Signed-off-by: David Edmondson <david.edmondson@oracle.com>
902636
Message-Id: <20200224101310.101169-2-david.edmondson@oracle.com>
902636
Reviewed-by: Max Reitz <mreitz@redhat.com>
902636
Signed-off-by: Max Reitz <mreitz@redhat.com>
902636
(cherry picked from commit 7788a319399f17476ff1dd43164c869e320820a2)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 block/curl.c | 31 +++++++++++++++++++++++++++----
902636
 1 file changed, 27 insertions(+), 4 deletions(-)
902636
902636
diff --git a/block/curl.c b/block/curl.c
902636
index f862993..f9ffb7f 100644
902636
--- a/block/curl.c
902636
+++ b/block/curl.c
902636
@@ -214,11 +214,34 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
902636
 {
902636
     BDRVCURLState *s = opaque;
902636
     size_t realsize = size * nmemb;
902636
-    const char *accept_line = "Accept-Ranges: bytes";
902636
+    const char *header = (char *)ptr;
902636
+    const char *end = header + realsize;
902636
+    const char *accept_ranges = "Accept-Ranges:";
902636
+    const char *bytes = "bytes";
902636
 
902636
-    if (realsize >= strlen(accept_line)
902636
-        && strncmp((char *)ptr, accept_line, strlen(accept_line)) == 0) {
902636
-        s->accept_range = true;
902636
+    if (realsize >= strlen(accept_ranges)
902636
+        && strncmp(header, accept_ranges, strlen(accept_ranges)) == 0) {
902636
+
902636
+        char *p = strchr(header, ':') + 1;
902636
+
902636
+        /* Skip whitespace between the header name and value. */
902636
+        while (p < end && *p && g_ascii_isspace(*p)) {
902636
+            p++;
902636
+        }
902636
+
902636
+        if (end - p >= strlen(bytes)
902636
+            && strncmp(p, bytes, strlen(bytes)) == 0) {
902636
+
902636
+            /* Check that there is nothing but whitespace after the value. */
902636
+            p += strlen(bytes);
902636
+            while (p < end && *p && g_ascii_isspace(*p)) {
902636
+                p++;
902636
+            }
902636
+
902636
+            if (p == end || !*p) {
902636
+                s->accept_range = true;
902636
+            }
902636
+        }
902636
     }
902636
 
902636
     return realsize;
902636
-- 
902636
1.8.3.1
902636