[dconf-editor] Fix a bug allowing to open bad paths.



commit 8bac7402a2ef611c48747653aa179d1e9b9ab297
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Sep 15 15:18:47 2018 +0200

    Fix a bug allowing to open bad paths.

 editor/bookmarks.vala       |  4 ++++
 editor/dconf-editor.vala    | 12 ++++++++++++
 editor/dconf-window.vala    | 20 ++++++++++++++++----
 editor/pathentry.vala       | 12 ++++++++++++
 editor/registry-search.vala |  3 ++-
 5 files changed, 46 insertions(+), 5 deletions(-)
---
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index 7427d0b..0b6c3ea 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -80,6 +80,8 @@ private class Bookmarks : MenuButton
         string [] unduplicated_bookmarks = {};
         foreach (string bookmark in all_bookmarks)
         {
+            if (DConfWindow.is_path_invalid (bookmark))
+                continue;
             if (bookmark in unduplicated_bookmarks)
                 continue;
             unduplicated_bookmarks += bookmark;
@@ -232,6 +234,8 @@ private class Bookmarks : MenuButton
         string [] unduplicated_bookmarks = new string [0];
         foreach (string bookmark in bookmarks)
         {
+            if (DConfWindow.is_path_invalid (bookmark))
+                continue;
             if (bookmark in unduplicated_bookmarks)
                 continue;
             unduplicated_bookmarks += bookmark;
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index e71910d..a17c38f 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -373,6 +373,9 @@ private class ConfigurationEditor : Gtk.Application
 
         if (arg0.has_prefix ("/"))
         {
+            if (arg0.contains ("//"))
+                return failure_double_slash (commands);
+
             Gtk.Window window = get_new_window (null, arg0, null);
             if (args.length == 2)
             {
@@ -414,6 +417,8 @@ private class ConfigurationEditor : Gtk.Application
                 simple_activation ();
                 return Posix.EXIT_FAILURE;
             }
+            if (((!) path).contains ("//"))
+                return failure_double_slash (commands);
         }
 
         Gtk.Window window = get_new_window (test_format [0], path, key_name);
@@ -421,6 +426,13 @@ private class ConfigurationEditor : Gtk.Application
         return Posix.EXIT_SUCCESS;
     }
 
+    private int failure_double_slash (ApplicationCommandLine commands)
+    {
+        commands.print (_("Cannot understand: given path contains ā€œ//ā€.\n"));
+        simple_activation ();
+        return Posix.EXIT_FAILURE;
+    }
+
     private int failure_space (ApplicationCommandLine commands)
     {
         commands.print (_("Cannot understand: space character in argument.\n"));
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 88eb423..ea2628c 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -118,8 +118,13 @@ private class DConfWindow : ApplicationWindow
 
         /* init current_path */
         bool restore_view = settings.get_boolean ("restore-view");
+        string? settings_saved_view = null;
         if (restore_view)
         {
+            settings_saved_view = settings.get_string ("saved-view");
+            if (((!) settings_saved_view).contains ("//"))
+                settings_saved_view = "/";
+
             string saved_path = settings.get_string ("saved-pathbar-path");
             string fallback_path = model.get_fallback_path (saved_path);
             /* path_widget.set_path (ModelUtils.is_folder_path (saved_path) ? ViewType.FOLDER : 
ViewType.OBJECT, saved_path);
@@ -136,7 +141,7 @@ private class DConfWindow : ApplicationWindow
                 assert_not_reached ();
 
             if (first_path == null && restore_view)
-                first_path = settings.get_string ("saved-view");
+                first_path = settings_saved_view;
         }
         else if (schemas_utility.is_relocatable_schema ((!) schema))
         {
@@ -144,7 +149,7 @@ private class DConfWindow : ApplicationWindow
             {
                 warning (_("Schema is relocatable, a path is needed."));
                 if (restore_view)
-                    first_path = settings.get_string ("saved-view");
+                    first_path = settings_saved_view;
             }
             else
             {
@@ -170,7 +175,7 @@ private class DConfWindow : ApplicationWindow
             {
                 warning (_("Schema is not installed on given path."));
                 if (restore_view)
-                    first_path = settings.get_string ("saved-view");
+                    first_path = settings_saved_view;
             }
             else if (key_name == null)
                 first_path = schema_path;
@@ -185,7 +190,7 @@ private class DConfWindow : ApplicationWindow
             if ((!) schema != "")
                 warning (_("Unknown schema ā€œ%sā€.").printf ((!) schema));
             if (restore_view)
-                first_path = settings.get_string ("saved-view");
+                first_path = settings_saved_view;
         }
 
         prepare_model ();
@@ -578,6 +583,8 @@ private class DConfWindow : ApplicationWindow
         {
             if (bookmark.has_prefix ("?"))
                 continue;
+            if (is_path_invalid (bookmark))
+                continue;
             if (ModelUtils.is_folder_path (bookmark))
                 continue;   // TODO check folder existence
 
@@ -677,6 +684,11 @@ private class DConfWindow : ApplicationWindow
     * * Path requests
     \*/
 
+    public static bool is_path_invalid (string path)
+    {
+        return path.has_prefix ("/") && path.contains ("//");
+    }
+
     private void request_folder (string full_name, string selected_or_empty = "", bool notify_missing = true)
     {
         string fallback_path = model.get_fallback_path (full_name);
diff --git a/editor/pathentry.vala b/editor/pathentry.vala
index 2b54087..4fa4c32 100644
--- a/editor/pathentry.vala
+++ b/editor/pathentry.vala
@@ -57,8 +57,20 @@ private class PathEntry : Box
         return search_entry.handle_event (event);
     }
 
+    private bool has_error_class = false;
     internal void set_path (ViewType type, string path)
     {
+        if (!has_error_class && DConfWindow.is_path_invalid (path))
+        {
+            has_error_class = true;
+            search_entry.get_style_context ().add_class ("error");
+        }
+        else if (has_error_class && !DConfWindow.is_path_invalid (path))
+        {
+            has_error_class = false;
+            search_entry.get_style_context ().remove_class ("error");
+        }
+
         current_path = path;
 //        if (type == ViewType.SEARCH)
     }
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index f87e2a0..bc09a95 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -149,7 +149,8 @@ private class RegistrySearch : RegistryList
     internal void start_search (string term)
         requires (current_path_if_search_mode != null)
     {
-        if (old_term != null && term == (!) old_term)
+        if ((old_term != null && term == (!) old_term)
+         || DConfWindow.is_path_invalid (term))
         {
             ensure_selection (key_list_box);
             return;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]