SDL: Fix unsafe sprintf usage

Translation strings come from external data sources and can cause
a stack buffer overflow here just by accidentally (or maliciously)
being too long.
This commit is contained in:
Colin Snover
2017-09-03 20:00:23 -05:00
parent a2b05b5c63
commit d2b4e16ab2
@@ -2446,20 +2446,20 @@ bool SurfaceSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) {
setFeatureState(OSystem::kFeatureAspectRatioCorrection, !_videoMode.aspectRatioCorrection);
endGFXTransaction();
#ifdef USE_OSD
char buffer[128];
Common::String message;
if (_videoMode.aspectRatioCorrection)
sprintf(buffer, "%s\n%d x %d -> %d x %d",
message = Common::String::format("%s\n%d x %d -> %d x %d",
_("Enabled aspect ratio correction"),
_videoMode.screenWidth, _videoMode.screenHeight,
_hwscreen->w, _hwscreen->h
);
else
sprintf(buffer, "%s\n%d x %d -> %d x %d",
message = Common::String::format("%s\n%d x %d -> %d x %d",
_("Disabled aspect ratio correction"),
_videoMode.screenWidth, _videoMode.screenHeight,
_hwscreen->w, _hwscreen->h
);
displayMessageOnOSD(buffer);
displayMessageOnOSD(message.c_str());
#endif
internUpdateScreen();
return true;
@@ -2526,14 +2526,13 @@ bool SurfaceSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) {
g++;
}
if (newScalerName) {
char buffer[128];
sprintf(buffer, "%s %s\n%d x %d -> %d x %d",
const Common::String message = Common::String::format(
"%s %s\n%d x %d -> %d x %d",
_("Active graphics filter:"),
newScalerName,
_videoMode.screenWidth, _videoMode.screenHeight,
_hwscreen->w, _hwscreen->h
);
displayMessageOnOSD(buffer);
_hwscreen->w, _hwscreen->h);
displayMessageOnOSD(message.c_str());
}
#endif
internUpdateScreen();