From 9fc5f30a93cc636938b098bc82aa0e8b43b31ccb Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Sat, 27 Aug 2022 19:28:22 +0200 Subject: [PATCH] Call fgInitAllowedPaths() between updates of aircraft paths and -set.xml parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fgInitAircraft() loads the aircraft -set.xml file, which calls ResourceManager::findPath() for each 'include=...' directive. In order to prevent such includes from triggering the new warning printed by ResourceManager::findPath(), call fgInitAllowedPaths() after the aircraft paths have been updated and before the -set.xml file is loaded. Thanks to Alan Teeder for reporting the problem. We can now probably remove the call to fgInitAllowedPaths() after processOptions() in fgStartNewReset() (I believe the newly-added call comes “soon enough”). Not doing so in this commit, though: let's fix problems before optimizing. --- src/Main/fg_init.cxx | 3 ++- src/Main/main.cxx | 1 + src/Main/util.cxx | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 84ec1d95f..ad9cfcc54 100755 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1394,7 +1394,7 @@ void fgStartNewReset() // Rebuild the lists of allowed paths for cases where a path comes from an // untrusted source, such as the global property tree (this uses $FG_HOME // and other paths set by Options::processOptions()). - fgInitAllowedPaths(); + fgInitAllowedPaths(); // FIXME: this call is probably not necessary anymore const auto& resMgr = simgear::EmbeddedResourceManager::instance(); // The language was (re)set in processOptions() @@ -1413,6 +1413,7 @@ void fgStartNewReset() fgGetNode("/sim")->removeChild("aircraft-dir"); fgInitAircraftPaths(true); + fgInitAllowedPaths(); // take the new aircraft paths into account fgInitAircraft(true, false /* not from launcher */); render = new FGRenderer(composite_viewer); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 2cbf2f4e5..4f8f2b0de 100755 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -703,6 +703,7 @@ int fgMainInit( int argc, char **argv ) fgInitSecureMode(); fgInitAircraftPaths(false); + fgInitAllowedPaths(); // take the new aircraft paths into account auto errorManager = globals->add_new_subsystem(SGSubsystemMgr::GENERAL); errorManager->preinit(); diff --git a/src/Main/util.cxx b/src/Main/util.cxx index 38fec73fc..2e8e15e94 100644 --- a/src/Main/util.cxx +++ b/src/Main/util.cxx @@ -78,6 +78,11 @@ fgGetLowPass (double current, double target, double timeratio) */ void fgInitAllowedPaths() { + static unsigned int fgInitAllowedPaths_nbCalls = 0; + fgInitAllowedPaths_nbCalls++; + SG_LOG(SG_GENERAL, SG_DEBUG, "fgInitAllowedPaths() started (call " << + fgInitAllowedPaths_nbCalls << ")"); + if(SGPath("ygjmyfvhhnvdoesnotexist").realpath().utf8Str() == "ygjmyfvhhnvdoesnotexist"){ // Abort in case this is used with older versions of realpath() // that don't normalize non-existent files, as that would be a security