]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-remote: set upper length bound when parsing incoming headers
authorLuca Boccassi <bluca@debian.org>
Sat, 9 Dec 2023 12:09:42 +0000 (12:09 +0000)
committerLuca Boccassi <bluca@debian.org>
Sat, 9 Dec 2023 13:17:02 +0000 (13:17 +0000)
CID#1529420

src/journal-remote/journal-gatewayd.c
src/journal-remote/journal-remote-main.c
src/journal-remote/journal-remote.h

index 9f0d0ec34af636cceedcceea5a7a7806b7ed4e70..ad1c46ac6ca27b488e5ad914f72e590d77043223 100644 (file)
@@ -22,6 +22,7 @@
 #include "fileio.h"
 #include "glob-util.h"
 #include "hostname-util.h"
+#include "journal-remote.h"
 #include "log.h"
 #include "logs-show.h"
 #include "main-func.h"
@@ -431,6 +432,11 @@ static int request_parse_range(
         if (!range)
                 return 0;
 
+        /* Safety upper bound to make Coverity happy. Apache2 has a default limit of 8KB:
+         * https://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize */
+        if (strlen(range) > JOURNAL_SERVER_MEMORY_MAX)
+                return -EINVAL;
+
         m->n_skip = 0;
         range_after_eq = startswith(range, "entries=");
         if (range_after_eq) {
index da0f20d3ce05ba0dee83a5fb10039fc2b7beee5a..6c09c068c8088e91b5a5a8cf838138d9df64370f 100644 (file)
@@ -374,7 +374,7 @@ static int setup_microhttpd_server(RemoteServer *s,
                 { MHD_OPTION_EXTERNAL_LOGGER, (intptr_t) microhttpd_logger},
                 { MHD_OPTION_NOTIFY_COMPLETED, (intptr_t) request_meta_free},
                 { MHD_OPTION_LISTEN_SOCKET, fd},
-                { MHD_OPTION_CONNECTION_MEMORY_LIMIT, 128*1024},
+                { MHD_OPTION_CONNECTION_MEMORY_LIMIT, JOURNAL_SERVER_MEMORY_MAX},
                 { MHD_OPTION_END},
                 { MHD_OPTION_END},
                 { MHD_OPTION_END},
index 8d73f95dc9c5bac4e5f388dcfe7538584541fc14..1c0cde4db344a544e07d285c99c1c367a2128aea 100644 (file)
@@ -48,6 +48,9 @@ struct RemoteServer {
 };
 extern RemoteServer *journal_remote_server_global;
 
+/* Used for MHD_OPTION_CONNECTION_MEMORY_LIMIT and header parsing cap */
+#define JOURNAL_SERVER_MEMORY_MAX 128U * 1024U
+
 int journal_remote_server_init(
                 RemoteServer *s,
                 const char *output,