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

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