anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

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

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