mirror of https://github.com/OpenTTD/OpenTTD
(svn r25499) [1.3] -Backport from trunk:
- Fix: Do not send encoded texts to names, but decode them into a plain C string and then pass them on [FS#5613] (r25489, r25488) - Fix: Do not allow control codes in names of things (signs, vehicles, towns, stations, etc), so they have a known maximum fixed size and are, by definition, the same for everyone (r25487) - Fix: Missing length validation for town and president names in script APIs (r25486)release/1.3
parent
c62e867b56
commit
d271dd9566
|
@ -251,17 +251,17 @@ static const Command _command_proc_table[] = {
|
|||
|
||||
DEF_CMD(CmdWantEnginePreview, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_WANT_ENGINE_PREVIEW
|
||||
|
||||
DEF_CMD(CmdRenameVehicle, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_VEHICLE
|
||||
DEF_CMD(CmdRenameEngine, CMD_STR_CTRL | CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_ENGINE
|
||||
DEF_CMD(CmdRenameVehicle, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_VEHICLE
|
||||
DEF_CMD(CmdRenameEngine, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_ENGINE
|
||||
|
||||
DEF_CMD(CmdRenameCompany, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_COMPANY
|
||||
DEF_CMD(CmdRenamePresident, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_PRESIDENT
|
||||
DEF_CMD(CmdRenameCompany, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_COMPANY
|
||||
DEF_CMD(CmdRenamePresident, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_PRESIDENT
|
||||
|
||||
DEF_CMD(CmdRenameStation, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_STATION
|
||||
DEF_CMD(CmdRenameDepot, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_DEPOT
|
||||
DEF_CMD(CmdRenameStation, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_STATION
|
||||
DEF_CMD(CmdRenameDepot, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_DEPOT
|
||||
|
||||
DEF_CMD(CmdPlaceSign, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN
|
||||
DEF_CMD(CmdRenameSign, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN
|
||||
DEF_CMD(CmdPlaceSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN
|
||||
DEF_CMD(CmdRenameSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN
|
||||
|
||||
DEF_CMD(CmdTurnRoadVeh, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_TURN_ROADVEH
|
||||
|
||||
|
@ -272,7 +272,7 @@ static const Command _command_proc_table[] = {
|
|||
DEF_CMD(CmdBuyCompany, 0, CMDT_MONEY_MANAGEMENT ), // CMD_BUY_COMANY
|
||||
|
||||
DEF_CMD(CmdFoundTown, CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_FOUND_TOWN; founding random town can fail only in exec run
|
||||
DEF_CMD(CmdRenameTown, CMD_STR_CTRL | CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_TOWN
|
||||
DEF_CMD(CmdRenameTown, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_TOWN
|
||||
DEF_CMD(CmdDoTownAction, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_DO_TOWN_ACTION
|
||||
DEF_CMD(CmdTownCargoGoal, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_TOWN_CARGO_GOAL
|
||||
DEF_CMD(CmdTownGrowthRate, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_TOWN_GROWTH_RATE
|
||||
|
@ -314,7 +314,7 @@ static const Command _command_proc_table[] = {
|
|||
DEF_CMD(CmdDepotMassAutoReplace, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_DEPOT_MASS_AUTOREPLACE
|
||||
DEF_CMD(CmdCreateGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CREATE_GROUP
|
||||
DEF_CMD(CmdDeleteGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_DELETE_GROUP
|
||||
DEF_CMD(CmdRenameGroup, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_GROUP
|
||||
DEF_CMD(CmdRenameGroup, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_GROUP
|
||||
DEF_CMD(CmdAddVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_VEHICLE_GROUP
|
||||
DEF_CMD(CmdAddSharedVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_SHARE_VEHICLE_GROUP
|
||||
DEF_CMD(CmdRemoveAllVehiclesGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_REMOVE_ALL_VEHICLES_GROUP
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidBaseStation(station_id));
|
||||
EnforcePrecondition(false, name != NULL);
|
||||
const char *text = name->GetEncodedText();
|
||||
const char *text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforcePrecondition(false, name != NULL);
|
||||
const char *text = name->GetEncodedText();
|
||||
const char *text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
@ -64,8 +64,9 @@
|
|||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforcePrecondition(false, name != NULL);
|
||||
const char *text = name->GetEncodedText();
|
||||
const char *text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_PRESIDENT, text);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
EnforcePrecondition(false, name != NULL);
|
||||
const char *text = name->GetEncodedText();
|
||||
const char *text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
|
|
@ -265,6 +265,8 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
|||
return false;
|
||||
}
|
||||
|
||||
assert(StrEmpty(text) || (GetCommandFlags(cmd) & CMD_STR_CTRL) != 0 || StrValid(text, text + strlen(text)));
|
||||
|
||||
/* Set the default callback to return a true/false result of the DoCommand */
|
||||
if (callback == NULL) callback = &ScriptInstance::DoCommandReturn;
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
EnforcePrecondition(false, IsValidSign(sign_id));
|
||||
EnforcePrecondition(false, name != NULL);
|
||||
const char *text = name->GetEncodedText();
|
||||
const char *text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
@ -72,7 +72,7 @@
|
|||
|
||||
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
|
||||
EnforcePrecondition(INVALID_SIGN, name != NULL);
|
||||
const char *text = name->GetEncodedText();
|
||||
const char *text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(INVALID_SIGN, text);
|
||||
EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
|
|
@ -11,9 +11,12 @@
|
|||
|
||||
#include "../../stdafx.h"
|
||||
#include "../../string_func.h"
|
||||
#include "../../strings_func.h"
|
||||
#include "script_text.hpp"
|
||||
#include "../../table/control_codes.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
ScriptText::ScriptText(HSQUIRRELVM vm) :
|
||||
ZeroedMemoryAllocator()
|
||||
{
|
||||
|
@ -191,3 +194,14 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
|||
|
||||
return p;
|
||||
}
|
||||
|
||||
const char *Text::GetDecodedText()
|
||||
{
|
||||
const char *encoded_text = this->GetEncodedText();
|
||||
if (encoded_text == NULL) return NULL;
|
||||
|
||||
static char buf[1024];
|
||||
::SetDParamStr(0, encoded_text);
|
||||
::GetString(buf, STR_JUST_RAW_STRING, lastof(buf));
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,13 @@ public:
|
|||
* @api -all
|
||||
*/
|
||||
virtual const char *GetEncodedText() = 0;
|
||||
|
||||
/**
|
||||
* Convert a #ScriptText into a decoded normal string.
|
||||
* @return A string (in a static buffer), or NULL.
|
||||
* @api -all
|
||||
*/
|
||||
const char *GetDecodedText();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,9 +43,10 @@
|
|||
CCountedPtr<Text> counter(text);
|
||||
|
||||
EnforcePrecondition(false, text != NULL);
|
||||
const char *encoded_text = text->GetEncodedText();
|
||||
const char *encoded_text = text->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, encoded_text);
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(encoded_text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, encoded_text);
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@
|
|||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, name != NULL);
|
||||
const char *text = name->GetEncodedText();
|
||||
const char *text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
|
Loading…
Reference in New Issue