Mercurial > hg > openttd
changeset 9914:711da94fe0d7 draft
(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.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 13 Aug 2008 06:22:04 +0000 |
parents | a1cc2bf90049 |
children | f0cea4aa2bf6 |
files | src/engine.cpp src/group_cmd.cpp src/players.cpp src/signs.cpp src/station_cmd.cpp src/town_cmd.cpp src/vehicle.cpp src/waypoint.cpp |
diffstat | 8 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/engine.cpp +++ b/src/engine.cpp @@ -487,7 +487,8 @@ */ 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);
--- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -170,7 +170,8 @@ */ 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;
--- a/src/players.cpp +++ b/src/players.cpp @@ -366,8 +366,7 @@ } 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;
--- a/src/signs.cpp +++ b/src/signs.cpp @@ -133,6 +133,8 @@ /* 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);
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2809,7 +2809,9 @@ */ 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;
--- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1394,7 +1394,7 @@ } /* 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 @@ */ 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);
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1502,7 +1502,8 @@ */ 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);
--- a/src/waypoint.cpp +++ b/src/waypoint.cpp @@ -389,6 +389,7 @@ 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) {