richardphibel / rpms / systemd

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