From afc52252725edfa81277a22ba5b715a45f8103e9 Mon Sep 17 00:00:00 2001 From: mfranz Date: Fri, 13 Jun 2008 10:52:47 +0000 Subject: [PATCH] - allow users to set fg-home dir via FG_HOME environment variable, but - don't allow to do that from any XML file. This is to prevent malign code from writing a new fg-home in ~/.fgfs/autosave.xml or other files in ~/.fgfs/. --- src/Main/fg_init.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 0c6c42ca3..9c94fd2e7 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -607,7 +607,18 @@ bool fgInitConfig ( int argc, char **argv ) { SGPath config( homedir ); config.append( ".fgfs" ); #endif - fgSetString("/sim/fg-home", config.c_str()); + const char *fg_home = getenv("FG_HOME"); + if (fg_home) + config = fg_home; + + // Set /sim/fg-home and don't allow malign code to override it until + // Nasal security is set up. Use FG_HOME if necessary. + SGPropertyNode *home = fgGetNode("/sim", true); + home->removeChild("fg-home", 0, false); + home = home->getChild("fg-home", 0, true); + home->setStringValue(config.c_str()); + home->setAttribute(SGPropertyNode::WRITE, false); + config.append( "autosave.xml" ); SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << config.str()); try {