1
0
Fork 0

(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
rubidium 2013-06-28 19:24:39 +00:00
parent c62e867b56
commit d271dd9566
10 changed files with 43 additions and 18 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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 &param_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;
}

View File

@ -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();
};
/**

View File

@ -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);
}

View File

@ -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);