Blame SOURCES/0202-journal-remote-do-not-request-Content-Length-if-Tran.patch

a3e2b5
From f551c05e4799386508e10f0f007251e426493a67 Mon Sep 17 00:00:00 2001
a3e2b5
From: Yu Watanabe <watanabe.yu+github@gmail.com>
a3e2b5
Date: Mon, 11 Mar 2019 12:27:18 +0900
a3e2b5
Subject: [PATCH] journal-remote: do not request Content-Length if
a3e2b5
 Transfer-Encoding is chunked
a3e2b5
a3e2b5
This fixes a bug introduced by 7fdb237f5473cb8fc2129e57e8a0039526dcb4fd.
a3e2b5
a3e2b5
Closes #11571.
a3e2b5
a3e2b5
(cherry picked from commit a289dfd69b3ff4bccdde93e84b67c947bafa27e1)
a3e2b5
a3e2b5
Resolves: #1708849
a3e2b5
---
a3e2b5
 src/journal-remote/journal-remote-main.c | 41 ++++++++++++++++--------
a3e2b5
 1 file changed, 27 insertions(+), 14 deletions(-)
a3e2b5
a3e2b5
diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c
a3e2b5
index 5b0bbba310..47fe9d7433 100644
a3e2b5
--- a/src/journal-remote/journal-remote-main.c
a3e2b5
+++ b/src/journal-remote/journal-remote-main.c
a3e2b5
@@ -254,6 +254,7 @@ static int request_handler(
a3e2b5
         const char *header;
a3e2b5
         int r, code, fd;
a3e2b5
         _cleanup_free_ char *hostname = NULL;
a3e2b5
+        bool chunked = false;
a3e2b5
         size_t len;
a3e2b5
 
a3e2b5
         assert(connection);
a3e2b5
@@ -279,21 +280,33 @@ static int request_handler(
a3e2b5
                 return mhd_respond(connection, MHD_HTTP_UNSUPPORTED_MEDIA_TYPE,
a3e2b5
                                    "Content-Type: application/vnd.fdo.journal is required.");
a3e2b5
 
a3e2b5
+        header = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "Transfer-Encoding");
a3e2b5
+        if (header) {
a3e2b5
+                if (!strcaseeq(header, "chunked"))
a3e2b5
+                        return mhd_respondf(connection, 0, MHD_HTTP_BAD_REQUEST,
a3e2b5
+                                            "Unsupported Transfer-Encoding type: %s", header);
a3e2b5
+
a3e2b5
+                chunked = true;
a3e2b5
+        }
a3e2b5
+
a3e2b5
         header = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "Content-Length");
a3e2b5
-        if (!header)
a3e2b5
-                return mhd_respond(connection, MHD_HTTP_LENGTH_REQUIRED,
a3e2b5
-                                   "Content-Length header is required.");
a3e2b5
-        r = safe_atozu(header, &len;;
a3e2b5
-        if (r < 0)
a3e2b5
-                return mhd_respondf(connection, r, MHD_HTTP_LENGTH_REQUIRED,
a3e2b5
-                                    "Content-Length: %s cannot be parsed: %m", header);
a3e2b5
-
a3e2b5
-        if (len > ENTRY_SIZE_MAX)
a3e2b5
-                /* When serialized, an entry of maximum size might be slightly larger,
a3e2b5
-                 * so this does not correspond exactly to the limit in journald. Oh well.
a3e2b5
-                 */
a3e2b5
-                return mhd_respondf(connection, 0, MHD_HTTP_PAYLOAD_TOO_LARGE,
a3e2b5
-                                    "Payload larger than maximum size of %u bytes", ENTRY_SIZE_MAX);
a3e2b5
+        if (header) {
a3e2b5
+                if (chunked)
a3e2b5
+                        return mhd_respond(connection, MHD_HTTP_BAD_REQUEST,
a3e2b5
+                                           "Content-Length must not specified when Transfer-Encoding type is 'chuncked'");
a3e2b5
+
a3e2b5
+                r = safe_atozu(header, &len;;
a3e2b5
+                if (r < 0)
a3e2b5
+                        return mhd_respondf(connection, r, MHD_HTTP_LENGTH_REQUIRED,
a3e2b5
+                                            "Content-Length: %s cannot be parsed: %m", header);
a3e2b5
+
a3e2b5
+                if (len > ENTRY_SIZE_MAX)
a3e2b5
+                        /* When serialized, an entry of maximum size might be slightly larger,
a3e2b5
+                         * so this does not correspond exactly to the limit in journald. Oh well.
a3e2b5
+                         */
a3e2b5
+                        return mhd_respondf(connection, 0, MHD_HTTP_PAYLOAD_TOO_LARGE,
a3e2b5
+                                            "Payload larger than maximum size of %u bytes", ENTRY_SIZE_MAX);
a3e2b5
+        }
a3e2b5
 
a3e2b5
         {
a3e2b5
                 const union MHD_ConnectionInfo *ci;