]> git.mxchange.org Git - flightgear.git/commitdiff
Normalize the allowed paths as well (fix Windows breakage)
authorRebecca N. Palmer <rebecca_palmer@zoho.com>
Fri, 13 Mar 2015 22:39:22 +0000 (22:39 +0000)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Fri, 13 Mar 2015 22:40:35 +0000 (22:40 +0000)
src/Main/util.cxx

index 15f7158d506d366913f08c8a55d517ef742d4940..c3bcdfec76e53a55bea850260d99d90b03bb0df3 100644 (file)
@@ -72,6 +72,39 @@ fgGetLowPass (double current, double target, double timeratio)
     return current;
 }
 
+// Normalize a path
+// Unlike SGPath::realpath, does not require that the file already exists,
+// but does require that it be below the starting point
+static std::string fgNormalizePath (const std::string& path)
+{
+    string_list path_parts;
+    char c;
+    std::string normed_path = "", this_part = "";
+    
+    for (int pos = 0; ; pos++) {
+        c = path[pos];
+        if (c == '\\') { c = '/'; }
+        if ((c == '/') || (c == 0)) {
+            if ((this_part == "/..") || (this_part == "..")) {
+                if (path_parts.empty()) { return ""; }
+                path_parts.pop_back();
+            } else if ((this_part != "/.") && (this_part != "/")) {
+                path_parts.push_back(this_part);
+            }
+            this_part = "";
+        }
+        if (c == 0) { break; }
+        this_part = this_part + c;
+    }
+    for( string_list::const_iterator it = path_parts.begin();
+                                     it != path_parts.end();
+                                   ++it )
+    {
+        normed_path.append(*it);
+    }
+    return normed_path;
+ }
+
 static string_list read_allowed_paths;
 static string_list write_allowed_paths;
 
@@ -83,14 +116,16 @@ void fgInitAllowedPaths()
 {
     read_allowed_paths.clear();
     write_allowed_paths.clear();
-    read_allowed_paths.push_back(globals->get_fg_root() + "/*");
-    read_allowed_paths.push_back(globals->get_fg_home() + "/*");
+    std::string fg_root = fgNormalizePath(globals->get_fg_root());
+    std::string fg_home = fgNormalizePath(globals->get_fg_home());
+    read_allowed_paths.push_back(fg_root + "/*");
+    read_allowed_paths.push_back(fg_home + "/*");
     string_list const aircraft_paths = globals->get_aircraft_paths();
     for( string_list::const_iterator it = aircraft_paths.begin();
                                      it != aircraft_paths.end();
                                    ++it )
     {
-        read_allowed_paths.push_back(*it + "/*");
+        read_allowed_paths.push_back(fgNormalizePath(*it) + "/*");
     }
 
     for( string_list::const_iterator it = read_allowed_paths.begin();
@@ -106,15 +141,15 @@ void fgInitAllowedPaths()
         }
     }
     write_allowed_paths.push_back("/tmp/*.xml");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/*.sav");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/*.log");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/cache/*");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/Export/*");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/state/*.xml");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/aircraft-data/*.xml");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/Wildfire/*.xml");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/runtime-jetways/*.xml");
-    write_allowed_paths.push_back(globals->get_fg_home() + "/Input/Joysticks/*.xml");
+    write_allowed_paths.push_back(fg_home + "/*.sav");
+    write_allowed_paths.push_back(fg_home + "/*.log");
+    write_allowed_paths.push_back(fg_home + "/cache/*");
+    write_allowed_paths.push_back(fg_home + "/Export/*");
+    write_allowed_paths.push_back(fg_home + "/state/*.xml");
+    write_allowed_paths.push_back(fg_home + "/aircraft-data/*.xml");
+    write_allowed_paths.push_back(fg_home + "/Wildfire/*.xml");
+    write_allowed_paths.push_back(fg_home + "/runtime-jetways/*.xml");
+    write_allowed_paths.push_back(fg_home + "/Input/Joysticks/*.xml");
     
     // Check that it works
     if(!fgValidatePath(globals->get_fg_home() + "/../no.log",true).empty() ||
@@ -133,40 +168,6 @@ void fgInitAllowedPaths()
     }
 }
 
-// Normalize a path
-// Unlike SGPath::realpath, does not require that the file already exists,
-// but does require that it be below the starting point
-static std::string fgNormalizePath (const std::string& path)
-{
-    string_list path_parts;
-    char c;
-    std::string normed_path = "", this_part = "";
-    
-    for (int pos = 0; ; pos++) {
-        c = path[pos];
-        if (c == '\\') { c = '/'; }
-        if ((c == '/') || (c == 0)) {
-            if ((this_part == "/..") || (this_part == "..")) {
-                if (path_parts.empty()) { return ""; }
-                path_parts.pop_back();
-            } else if ((this_part != "/.") && (this_part != "/")) {
-                path_parts.push_back(this_part);
-            }
-            this_part = "";
-        }
-        if (c == 0) { break; }
-        this_part = this_part + c;
-    }
-    for( string_list::const_iterator it = path_parts.begin();
-                                     it != path_parts.end();
-                                   ++it )
-    {
-        normed_path.append(*it);
-    }
-    return normed_path;
- }
-
-
 // Check whether Nasal is allowed to access a path
 std::string fgValidatePath (const std::string& path, bool write)
 {