Skip to content

Commit e80fc22

Browse files
authoredOct 6, 2020
Prevent games from setting secure settings (#10460)
1 parent f46509d commit e80fc22

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed
 

‎src/content/subgames.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3434
// The maximum number of identical world names allowed
3535
#define MAX_WORLD_NAMES 100
3636

37+
namespace
38+
{
39+
3740
bool getGameMinetestConfig(const std::string &game_path, Settings &conf)
3841
{
3942
std::string conf_path = game_path + DIR_DELIM + "minetest.conf";
4043
return conf.readConfigFile(conf_path.c_str());
4144
}
4245

46+
}
47+
4348
struct GameFindPath
4449
{
4550
std::string path;
@@ -330,8 +335,11 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
330335
// files that were loaded before.
331336
g_settings->clearDefaults();
332337
set_default_settings(g_settings);
338+
333339
Settings game_defaults;
334340
getGameMinetestConfig(gamespec.path, game_defaults);
341+
game_defaults.removeSecureSettings();
342+
335343
g_settings->overrideDefaults(&game_defaults);
336344

337345
infostream << "Initializing world at " << final_path << std::endl;

‎src/content/subgames.h

-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ struct SubgameSpec
5353
bool isValid() const { return (!id.empty() && !path.empty()); }
5454
};
5555

56-
// minetest.conf
57-
bool getGameMinetestConfig(const std::string &game_path, Settings &conf);
58-
5956
SubgameSpec findSubgame(const std::string &id);
6057
SubgameSpec findWorldSubgame(const std::string &world_path);
6158

‎src/settings.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,19 @@ void Settings::deregisterChangedCallback(const std::string &name,
10391039
}
10401040
}
10411041

1042+
void Settings::removeSecureSettings()
1043+
{
1044+
for (const auto &name : getNames()) {
1045+
if (name.compare(0, 7, "secure.") != 0)
1046+
continue;
1047+
1048+
errorstream << "Secure setting " << name
1049+
<< " isn't allowed, so was ignored."
1050+
<< std::endl;
1051+
remove(name);
1052+
}
1053+
}
1054+
10421055
void Settings::doCallbacks(const std::string &name) const
10431056
{
10441057
MutexAutoLock lock(m_callback_mutex);

‎src/settings.h

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ class Settings {
207207
void deregisterChangedCallback(const std::string &name,
208208
SettingsChangedCallback cbf, void *userdata = NULL);
209209

210+
void removeSecureSettings();
211+
210212
private:
211213
/***********************
212214
* Reading and writing *

0 commit comments

Comments
 (0)
Please sign in to comment.