From 2d94337e1ac754f6181d537708fe3a187d2c7400 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 13 Aug 2008 06:22:04 +0000 Subject: (svn r14064) -Fix [FS#1752]: check for the length of strings (in bytes) in the command. Checking for the length in pixels is impossible because that differs per client. --- src/engine.cpp | 3 ++- src/group_cmd.cpp | 3 ++- src/players.cpp | 3 +-- src/signs.cpp | 2 ++ src/station_cmd.cpp | 4 +++- src/town_cmd.cpp | 5 +++-- src/vehicle.cpp | 3 ++- src/waypoint.cpp | 1 + 8 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/engine.cpp b/src/engine.cpp index 3808c46a8..8f70f5109 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -487,7 +487,8 @@ static bool IsUniqueEngineName(const char *name) */ CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (!IsEngineIndex(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; + if (!IsEngineIndex(p1)) return CMD_ERROR; + if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR; if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 331feda34..44bfd12c1 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -170,7 +170,8 @@ static bool IsUniqueGroupName(const char *name) */ CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (!IsValidGroupID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; + if (!IsValidGroupID(p1)) return CMD_ERROR; + if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR; Group *g = GetGroup(p1); if (g->owner != _current_player) return CMD_ERROR; diff --git a/src/players.cpp b/src/players.cpp index d8e8ad685..e42d8d329 100644 --- a/src/players.cpp +++ b/src/players.cpp @@ -366,8 +366,7 @@ verify_name:; } GetString(buffer, str, lastof(buffer)); - if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 150) - goto bad_town_name; + if (strlen(buffer) >= MAX_LENGTH_COMPANY_NAME_BYTES) goto bad_town_name; set_name:; p->name_1 = str; diff --git a/src/signs.cpp b/src/signs.cpp index 369295a60..b514e2ab1 100644 --- a/src/signs.cpp +++ b/src/signs.cpp @@ -133,6 +133,8 @@ CommandCost CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) /* If _cmd_text 0 means the new text for the sign is non-empty. * So rename the sign. If it is empty, it has no name, so delete it */ if (!StrEmpty(_cmd_text)) { + if (strlen(_cmd_text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR; + if (flags & DC_EXEC) { Sign *si = GetSign(p1); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 5ba071c21..8f8ef13b6 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2809,7 +2809,9 @@ static bool IsUniqueStationName(const char *name) */ CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (!IsValidStationID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; + if (!IsValidStationID(p1)) + if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_STATION_NAME_BYTES) return CMD_ERROR; + Station *st = GetStation(p1); if (!CheckOwnership(st->owner)) return CMD_ERROR; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 4d5917562..3532fe3c7 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1394,7 +1394,7 @@ restart: } /* Check size and width */ - if (strlen(buf1) >= 31 || GetStringBoundingBox(buf1).width > 130) continue; + if (strlen(buf1) >= MAX_LENGTH_TOWN_NAME_BYTES || GetStringBoundingBox(buf1).width > MAX_LENGTH_TOWN_NAME_PIXELS) continue; FOR_ALL_TOWNS(t2) { /* We can't just compare the numbers since @@ -2093,7 +2093,8 @@ static bool IsUniqueTownName(const char *name) */ CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (!IsValidTownID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; + if (!IsValidTownID(p1)) return CMD_ERROR; + if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR; if (!IsUniqueTownName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 305544137..36f3db9e3 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1502,7 +1502,8 @@ static bool IsUniqueVehicleName(const char *name) */ CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (!IsValidVehicleID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; + if (!IsValidVehicleID(p1)) return CMD_ERROR; + if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR; Vehicle *v = GetVehicle(p1); diff --git a/src/waypoint.cpp b/src/waypoint.cpp index ac81cc45d..1518176a7 100644 --- a/src/waypoint.cpp +++ b/src/waypoint.cpp @@ -389,6 +389,7 @@ CommandCost CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2 if (!CheckTileOwnership(wp->xy)) return CMD_ERROR; if (!StrEmpty(_cmd_text)) { + if (strlen(_cmd_text) >= MAX_LENGTH_WAYPOINT_NAME_BYTES) return CMD_ERROR; if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); if (flags & DC_EXEC) { -- cgit v1.2.3-70-g09d2