ishcherb / rpms / abrt

Forked from rpms/abrt 6 years ago
Clone
fa19501
From 23c800077fb6e821d54080ccc5d1258f37fcd8d4 Mon Sep 17 00:00:00 2001
fa19501
From: Jakub Filak <jfilak@redhat.com>
fa19501
Date: Mon, 27 Apr 2015 07:52:00 +0200
fa19501
Subject: [PATCH] dbus: report invalid element names
fa19501
fa19501
Return D-Bus error in case of invalid problem element name.
fa19501
fa19501
Related: #1214451
fa19501
fa19501
Signed-off-by: Jakub Filak <jfilak@redhat.com>
fa19501
---
fa19501
 src/dbus/abrt-dbus.c | 35 +++++++++++++++++++++++++----------
fa19501
 1 file changed, 25 insertions(+), 10 deletions(-)
fa19501
fa19501
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
fa19501
index 0f7ac2d..489d273 100644
fa19501
--- a/src/dbus/abrt-dbus.c
fa19501
+++ b/src/dbus/abrt-dbus.c
fa19501
@@ -158,6 +158,21 @@ bool allowed_problem_dir(const char *dir_name)
fa19501
     return true;
fa19501
 }
fa19501
 
fa19501
+bool allowed_problem_element(GDBusMethodInvocation *invocation, const char *element)
fa19501
+{
fa19501
+    if (str_is_correct_filename(element))
fa19501
+        return true;
fa19501
+
fa19501
+    log_notice("'%s' is not a valid element name", element);
fa19501
+    char *error = xasprintf(_("'%s' is not a valid element name"), element);
fa19501
+    g_dbus_method_invocation_return_dbus_error(invocation,
fa19501
+            "org.freedesktop.problems.InvalidElement",
fa19501
+            error);
fa19501
+
fa19501
+    free(error);
fa19501
+    return false;
fa19501
+}
fa19501
+
fa19501
 static char *handle_new_problem(GVariant *problem_info, uid_t caller_uid, char **error)
fa19501
 {
fa19501
     problem_data_t *pd = problem_data_new();
fa19501
@@ -627,17 +642,8 @@ static void handle_method_call(GDBusConnection *connection,
fa19501
 
fa19501
         g_variant_get(parameters, "(&s&s&s)", &problem_id, &element, &value);
fa19501
 
fa19501
-        if (element == NULL || element[0] == '\0' || strlen(element) > 64)
fa19501
-        {
fa19501
-            log_notice("'%s' is not a valid element name of '%s'", element, problem_id);
fa19501
-            char *error = xasprintf(_("'%s' is not a valid element name"), element);
fa19501
-            g_dbus_method_invocation_return_dbus_error(invocation,
fa19501
-                                              "org.freedesktop.problems.InvalidElement",
fa19501
-                                              error);
fa19501
-
fa19501
-            free(error);
fa19501
+        if (!allowed_problem_element(invocation, element))
fa19501
             return;
fa19501
-        }
fa19501
 
fa19501
         struct dump_dir *dd = open_directory_for_modification_of_element(
fa19501
                                     invocation, caller_uid, problem_id, element);
fa19501
@@ -686,6 +692,9 @@ static void handle_method_call(GDBusConnection *connection,
fa19501
 
fa19501
         g_variant_get(parameters, "(&s&s)", &problem_id, &element);
fa19501
 
fa19501
+        if (!allowed_problem_element(invocation, element))
fa19501
+            return;
fa19501
+
fa19501
         struct dump_dir *dd = open_directory_for_modification_of_element(
fa19501
                                     invocation, caller_uid, problem_id, element);
fa19501
         if (!dd)
fa19501
@@ -718,6 +727,9 @@ static void handle_method_call(GDBusConnection *connection,
fa19501
 
fa19501
         g_variant_get(parameters, "(&s&s)", &problem_id, &element);
fa19501
 
fa19501
+        if (!allowed_problem_element(invocation, element))
fa19501
+            return;
fa19501
+
fa19501
         struct dump_dir *dd = open_dump_directory(invocation, caller, caller_uid,
fa19501
                 problem_id, DD_OPEN_READONLY, OPEN_AUTH_ASK);
fa19501
         if (!dd)
fa19501
@@ -790,6 +802,9 @@ static void handle_method_call(GDBusConnection *connection,
fa19501
         g_variant_get_child(parameters, 3, "x", &timestamp_to);
fa19501
         g_variant_get_child(parameters, 4, "b", &all;;
fa19501
 
fa19501
+        if (!allowed_problem_element(invocation, element))
fa19501
+            return;
fa19501
+
fa19501
         if (all && polkit_check_authorization_dname(caller, "org.freedesktop.problems.getall") == PolkitYes)
fa19501
             caller_uid = 0;
fa19501
 
fa19501
-- 
fa19501
2.1.0
fa19501