PEGASUS: Limit the accepted characters in save file names

This commit is contained in:
Matthew Hoops 2013-02-04 14:06:29 -05:00
parent 49ebbfd9dc
commit 89d574e6d0

View File

@ -657,7 +657,23 @@ Common::Error PegasusEngine::loadGameState(int slot) {
return valid ? Common::kNoError : Common::kUnknownError;
}
static bool isValidSaveFileChar(char c) {
// Limit it to letters, digits, and a few other characters that should be safe
return Common::isAlnum(c) || c == ' ' || c == '_' || c == '+' || c == '-' || c == '.';
}
static bool isValidSaveFileName(const Common::String &desc) {
for (uint32 i = 0; i < desc.size(); i++)
if (!isValidSaveFileChar(desc[i]))
return false;
return true;
}
Common::Error PegasusEngine::saveGameState(int slot, const Common::String &desc) {
if (!isValidSaveFileName(desc))
return Common::Error(Common::kCreatingFileFailed, _("Invalid save file name"));
Common::String output = Common::String::format("pegasus-%s.sav", desc.c_str());
Common::OutSaveFile *saveFile = _saveFileMan->openForSaving(output, false);
if (!saveFile)