]> git.mxchange.org Git - flightgear.git/commitdiff
Fix a bug for allowed paths
authorTorsten Dreyer <torsten@t3r.de>
Tue, 12 Jan 2016 10:19:26 +0000 (11:19 +0100)
committerTorsten Dreyer <torsten@t3r.de>
Tue, 12 Jan 2016 10:19:26 +0000 (11:19 +0100)
Under some conditions on my system
aircraft_paths.begin() was equal to scenery_paths.end()
This resulted in neither of them being added to read_allowed_paths
followed by failure to load Nasal scripts from the aircraft directory.

This might happen, if scenery_paths gets allocated just before aircraft_paths
in memory.
Better loop across the desired lists instead of using fancy tricks with
the iterator.

src/Main/util.cxx

index 6bc4ddb50f36093591778d1ee750c91bb7a56167..523893b5b0e8025499f655c207b477cf395f90f3 100644 (file)
@@ -106,24 +106,25 @@ void fgInitAllowedPaths()
     // not plain fg_scenery, to avoid making
     // /sim/terrasync/scenery-dir a security hole
 
-    for( string_list::const_iterator it = aircraft_paths.begin();;++it )
+    const string_list * path_lists_to_add[] = {
+      &aircraft_paths,
+      &scenery_paths
+    };
+
+    for( size_t i = 0; i < sizeof(path_lists_to_add)/sizeof(path_lists_to_add[0]); i++ )
     {
-      if (it == aircraft_paths.end()) {
-        it = scenery_paths.begin();
-      }
-      if (it == scenery_paths.end()) {
-        break; // here rather than in the loop condition because
-               // scenery_paths may be empty
+      for( string_list::const_iterator it = path_lists_to_add[i]->begin(); it != path_lists_to_add[i]->end();++it )
+      {
+        // if we get the initialization order wrong, better to have an
+        // obvious error than a can-read-everything security hole...
+          if (it->empty() || fg_root.empty() || fg_home.empty()){
+              flightgear::fatalMessageBox("Nasal initialization error",
+                 "Empty string in FG_ROOT, FG_HOME, FG_AIRCRAFT or FG_SCENERY",
+                                   "or fgInitAllowedPaths() called too early");
+              exit(-1);
+          }
+          read_allowed_paths.push_back(SGPath(*it).realpath() + sep + "*");
       }
-      // if we get the initialization order wrong, better to have an
-      // obvious error than a can-read-everything security hole...
-        if (it->empty() || fg_root.empty() || fg_home.empty()){
-            flightgear::fatalMessageBox("Nasal initialization error",
-               "Empty string in FG_ROOT, FG_HOME, FG_AIRCRAFT or FG_SCENERY",
-                                 "or fgInitAllowedPaths() called too early");
-            exit(-1);
-        }
-        read_allowed_paths.push_back(SGPath(*it).realpath() + sep + "*");
     }
 
     write_allowed_paths.push_back(fg_home + sep + "*.sav");