From 30a390b7598022df82a469c7805dc4a05abf64e9 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 24 Nov 2013 19:46:16 +0000 Subject: [PATCH] (svn r26092) -Fix [FS#5818]: prevent scripts from crashing OpenTTD when they send text with command codes to user editable texts such as sign and station names --- src/command.cpp | 2 +- src/script/api/script_object.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index 5710f0bb64..2585eda00d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -219,7 +219,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdRemoveFromRailStation, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_FROM_RAIL_STATION DEF_CMD(CmdConvertRail, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_CONVERT_RAILD DEF_CMD(CmdBuildRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_RAIL_WAYPOINT - DEF_CMD(CmdRenameWaypoint, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_WAYPOINT + DEF_CMD(CmdRenameWaypoint, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_WAYPOINT DEF_CMD(CmdRemoveFromRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_FROM_RAIL_WAYPOINT DEF_CMD(CmdBuildRoadStop, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_ROAD_STOP diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index 6d4140b2a3..d9aefca3cf 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -287,7 +287,11 @@ ScriptObject::ActiveInstance::~ActiveInstance() return false; } - assert(StrEmpty(text) || (GetCommandFlags(cmd) & CMD_STR_CTRL) != 0 || StrValid(text, text + strlen(text))); + if (!StrEmpty(text) && (GetCommandFlags(cmd) & CMD_STR_CTRL) == 0) { + /* The string must be valid, i.e. not contain special codes. Since some + * can be made with GSText, make sure the control codes are removed. */ + str_validate(text, text + strlen(text)), SVS_NONE); + } /* Set the default callback to return a true/false result of the DoCommand */ if (callback == NULL) callback = &ScriptInstance::DoCommandReturn;