Blame SOURCES/0003-common-Handle-use-of-NULL-string-in-web_response_fil.patch

15e88b
From 36285fde744edd164f1f18990e892f5da92ca1ca Mon Sep 17 00:00:00 2001
15e88b
From: Stef Walter <stefw@redhat.com>
15e88b
Date: Sun, 9 Sep 2018 09:33:00 +0200
15e88b
Subject: [PATCH 1/2] common: Handle use of NULL string in web_response_file
15e88b
15e88b
The function g_uri_unescape_string can return a NULL response
15e88b
if the escaped string is invalid.
15e88b
15e88b
Closes #10028
15e88b
---
15e88b
 src/common/cockpitwebresponse.c |  2 +-
15e88b
 src/common/test-webresponse.c   | 18 ++++++++++++++++++
15e88b
 2 files changed, 19 insertions(+), 1 deletion(-)
15e88b
15e88b
diff --git a/src/common/cockpitwebresponse.c b/src/common/cockpitwebresponse.c
15e88b
index 0fee95920..d156bc319 100644
15e88b
--- a/src/common/cockpitwebresponse.c
15e88b
+++ b/src/common/cockpitwebresponse.c
15e88b
@@ -1300,7 +1300,7 @@ web_response_file (CockpitWebResponse *response,
15e88b
 
15e88b
   /* Someone is trying to escape the root directory, or access hidden files? */
15e88b
   unescaped = g_uri_unescape_string (escaped, NULL);
15e88b
-  if (strstr (unescaped, "/.") || strstr (unescaped, "../") || strstr (unescaped, "//"))
15e88b
+  if (!unescaped || strstr (unescaped, "/.") || strstr (unescaped, "../") || strstr (unescaped, "//"))
15e88b
     {
15e88b
       g_debug ("%s: invalid path request", escaped);
15e88b
       cockpit_web_response_error (response, 404, NULL, "Not Found");
15e88b
diff --git a/src/common/test-webresponse.c b/src/common/test-webresponse.c
15e88b
index fd2793dc3..4ad72b967 100644
15e88b
--- a/src/common/test-webresponse.c
15e88b
+++ b/src/common/test-webresponse.c
15e88b
@@ -293,6 +293,22 @@ test_file_breakout_denied (TestCase *tc,
15e88b
   free (root);
15e88b
 }
15e88b
 
15e88b
+static void
15e88b
+test_file_encoding_denied (TestCase *tc,
15e88b
+                           gconstpointer user_data)
15e88b
+{
15e88b
+  gchar *root = realpath ( SRCDIR "/src", NULL);
15e88b
+  const gchar *roots[] = { root, NULL };
15e88b
+  const gchar *breakout = "/common/Makefile-common.am%00";
15e88b
+  gchar *check = g_build_filename (roots[0], "common", "Makefile-common.am", NULL);
15e88b
+  g_assert (root);
15e88b
+  g_assert (g_file_test (check, G_FILE_TEST_EXISTS));
15e88b
+  g_free (check);
15e88b
+  cockpit_web_response_file (tc->response, breakout, roots);
15e88b
+  cockpit_assert_strmatch (output_as_string (tc), "HTTP/1.1 404*");
15e88b
+  free (root);
15e88b
+}
15e88b
+
15e88b
 static void
15e88b
 test_file_breakout_non_existant (TestCase *tc,
15e88b
                                  gconstpointer user_data)
15e88b
@@ -1422,6 +1438,8 @@ main (int argc,
15e88b
               setup, test_file_access_denied, teardown);
15e88b
   g_test_add ("/web-response/file/breakout-denied", TestCase, NULL,
15e88b
               setup, test_file_breakout_denied, teardown);
15e88b
+  g_test_add ("/web-response/file/invalid-encoding-denied", TestCase, NULL,
15e88b
+              setup, test_file_encoding_denied, teardown);
15e88b
   g_test_add ("/web-response/file/breakout-non-existant", TestCase, NULL,
15e88b
               setup, test_file_breakout_non_existant, teardown);
15e88b
   g_test_add ("/web-reponse/file/template", TestCase, &template_fixture,
15e88b
-- 
15e88b
2.17.1
15e88b