From 8b9d4348f8e590de5693f6dd2ea0df0f5a4e445a Mon Sep 17 00:00:00 2001 From: D G Turner Date: Thu, 14 Nov 2013 18:35:03 +0000 Subject: 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. --- backends/platform/sdl/posix/posix.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'backends/platform/sdl') 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; } -- cgit v1.2.3