aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorD G Turner2013-11-14 18:35:03 +0000
committerD G Turner2013-11-14 18:35:03 +0000
commit8b9d4348f8e590de5693f6dd2ea0df0f5a4e445a (patch)
tree3ea0240373a005ef3e1c5c0b8340e341db464017
parented68aea5ba2b7d68fa22b82536e36527cdfe36c2 (diff)
downloadscummvm-rg350-8b9d4348f8e590de5693f6dd2ea0df0f5a4e445a.tar.gz
scummvm-rg350-8b9d4348f8e590de5693f6dd2ea0df0f5a4e445a.tar.bz2
scummvm-rg350-8b9d4348f8e590de5693f6dd2ea0df0f5a4e445a.zip
SDL: Fix bug where config file path could exceed maximum path length.
The fix is the change in the MAXPATHLEN check, but have also migrated this to Common::String to make the fix easier. Thanks to klusark for pointing out this problem.
-rw-r--r--backends/platform/sdl/posix/posix.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp
index 7a8b1e7b70..954f404ac6 100644
--- a/backends/platform/sdl/posix/posix.cpp
+++ b/backends/platform/sdl/posix/posix.cpp
@@ -80,15 +80,16 @@ bool OSystem_POSIX::hasFeature(Feature f) {
}
Common::String OSystem_POSIX::getDefaultConfigFileName() {
- char configFile[MAXPATHLEN];
+ Common::String configFile;
// On POSIX type systems, by default we store the config file inside
// to the HOME directory of the user.
const char *home = getenv("HOME");
- if (home != NULL && strlen(home) < MAXPATHLEN)
- snprintf(configFile, MAXPATHLEN, "%s/%s", home, _baseConfigName.c_str());
- else
- strcpy(configFile, _baseConfigName.c_str());
+ if (home != NULL && (strlen(home) + 1 + _baseConfigName.size()) < MAXPATHLEN) {
+ configFile = Common::String::format("%s/%s", home, _baseConfigName.c_str());
+ } else {
+ configFile = _baseConfigName;
+ }
return configFile;
}