Skip to content

Commit 26f5d4c

Browse files
committed
Expand list of illegal chars, plus PR feedback
1 parent 45fb971 commit 26f5d4c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,12 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
289289
}
290290
#endif
291291

292-
// We're the host, so first validate the name
293-
if (wcschr(msg->name, L',') || wcschr(msg->name, L';') || wcschr(msg->name, L':'))
292+
// TheSuperHackers @bugfix slurmlord 18/09/2025 need to validate the name of the connecting player before
293+
// allowing them to join to prevent messing up the format of game state string
294+
constexpr WideChar IllegalNameChars[] = L",:;|\f\n\r\t\v";
295+
if (canJoin && (wcscspn(msg->name, IllegalNameChars) || wcsspn(msg->name, L" ") == wcslen(msg->name)))
294296
{
295-
// Commas, colons or semicolons should not be in a player name.
297+
// Commas, colons, semicolons etc. should not be in a player name. It should also not consist of only space characters.
296298
// If so, just deny with a duplicate name error (for backwards compatibility with retail)
297299
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
298300
reply.GameNotJoined.reason = LANAPIInterface::RET_DUPLICATE_NAME;
@@ -301,7 +303,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
301303
canJoin = false;
302304

303305
DEBUG_LOG(("LANAPI::handleRequestJoin - join denied because of illegal characters in the player name."));
304-
}
306+
}
305307

306308
// Then see if the player has a duplicate name
307309
for (player = 0; canJoin && player<MAX_SLOTS; ++player)

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,12 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
290290
}
291291
#endif
292292

293-
// We're the host, so first validate the name
294-
if (wcschr(msg->name, L',') || wcschr(msg->name, L';') || wcschr(msg->name, L':'))
293+
// TheSuperHackers @bugfix slurmlord 18/09/2025 need to validate the name of the connecting player before
294+
// allowing them to join to prevent messing up the format of game state string
295+
constexpr WideChar IllegalNameChars[] = L",:;|\f\n\r\t\v";
296+
if (canJoin && (wcscspn(msg->name, IllegalNameChars) || wcsspn(msg->name, L" ") == wcslen(msg->name)))
295297
{
296-
// Commas, colons or semicolons should not be in a player name.
298+
// Commas, colons, semicolons etc. should not be in a player name. It should also not consist of only space characters.
297299
// If so, just deny with a duplicate name error (for backwards compatibility with retail)
298300
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
299301
reply.GameNotJoined.reason = LANAPIInterface::RET_DUPLICATE_NAME;

0 commit comments

Comments
 (0)