fix(logic): Improve validation of MSG_DO_SPECIAL_POWER and variants in GameLogicDispatch#2380
Conversation
…n GameLogicDispatch
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | Adds ownership validation (player vs. source object) for MSG_DO_SPECIAL_POWER and its three variants; change is logically sound and consistent with existing validation patterns elsewhere in the same function, with only minor trailing-whitespace nits in three of the four hunks. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[logicMessageDispatcher receives MSG_DO_SPECIAL_POWER variant] --> B[Extract sourceID from message]
B --> C{source = findObjectByID sourceID}
C -- "source == nullptr" --> D[Use currentlySelectedGroup fallback]
C -- "source != nullptr" --> E{source->getControllingPlayer\n== thisPlayer?}
E -- "No (invalid owner)" --> F[DEBUG_CRASH in debug builds]
F --> G[break: silently discard message in release]
E -- "Yes (valid owner)" --> H[Create AIGroup with source]
H --> I[Execute groupDoSpecialPower variant]
I --> J[Cleanup AIGroup]
D --> K{currentlySelectedGroup != nullptr?}
K -- "Yes" --> L[Execute groupDoSpecialPower variant on selection]
K -- "No" --> M[No-op]
Last reviewed commit: 2087cec
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Outdated
Show resolved
Hide resolved
| Player *player = ThePlayerList->getNthPlayer(msg->getPlayerIndex()); | ||
| if ( player && source->getControllingPlayer() != player ) |
There was a problem hiding this comment.
You can use thisPlayer: if ( source->getControllingPlayer() != thisPlayer ), multiple times.
There was a problem hiding this comment.
Good one. There are a lot of instances of ThePlayerList->getNthPlayer(msg->getPlayerIndex()) in this class, some null checked, others not
There was a problem hiding this comment.
Perhaps the other places that do null checks should be replaced with a single check way up in logicMessageDispatcher, but that's for another PR.
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Show resolved
Hide resolved
|
Does this resolve an actual bug/crash or is it solving a potential issue in the future? |
This PR improves the stability of network games by validating the origin of source objects in
MSG_DO_SPECIAL_POWERand related MSG variants inGameLogicDispatch. Tested on ~1k replays.Todo