From: Torsten Dreyer Date: Tue, 12 Jan 2016 10:19:26 +0000 (+0100) Subject: Fix a bug for allowed paths X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=296849cf3d85d720e4c921b5a58a3595be7bbca0;p=flightgear.git Fix a bug for allowed paths 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. --- diff --git a/src/Main/util.cxx b/src/Main/util.cxx index 6bc4ddb50..523893b5b 100644 --- a/src/Main/util.cxx +++ b/src/Main/util.cxx @@ -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");