-
Notifications
You must be signed in to change notification settings - Fork 151
fix: Resolve crash by initializing debris shadow name to an empty string #2221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Greptile Overview
|
| Filename | Overview |
|---|---|
| Generals/Code/GameEngine/Include/GameClient/Shadow.h | Added default constructor to ShadowTypeInfo that initializes all members to safe defaults, preventing use of garbage data |
| GeneralsMD/Code/GameEngine/Include/GameClient/Shadow.h | Added default constructor to ShadowTypeInfo that initializes all members to safe defaults, preventing use of garbage data |
| Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDebrisDraw.cpp | Changed to use constructor initialization instead of uninitialized struct, removing redundant manual zero assignments |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDebrisDraw.cpp | Changed to use constructor initialization instead of uninitialized struct, removing redundant manual zero assignments |
Sequence Diagram
sequenceDiagram
participant Code as Calling Code
participant ST as ShadowTypeInfo
participant SM as W3DShadowManager
participant PS as W3DProjectedShadow
Note over Code,PS: Before Fix: Uninitialized Memory
Code->>ST: Shadow::ShadowTypeInfo shadowInfo
Note over ST: m_ShadowName contains garbage data
Code->>ST: shadowInfo.m_type = SHADOW_DECAL
Code->>SM: addShadow(&shadowInfo)
SM->>PS: Check shadowInfo->m_ShadowName[0] != '\0'
Note over PS: Garbage data causes check to pass!
PS->>PS: strlen(shadowInfo->m_ShadowName)
Note over PS: strlen reads garbage, may exceed bounds
PS->>PS: strcpy(texture_name, shadowInfo->m_ShadowName)
Note over PS: Invalid texture name copied
PS-->>Code: CRASH! Invalid texture name used
Note over Code,PS: After Fix: Properly Initialized
Code->>ST: Shadow::ShadowTypeInfo shadowInfo = Shadow::ShadowTypeInfo()
Note over ST: Constructor sets m_ShadowName[0] = '\0'
Note over ST: All members initialized to safe defaults
Code->>ST: shadowInfo.m_type = SHADOW_DECAL
Code->>SM: addShadow(&shadowInfo)
SM->>PS: Check shadowInfo->m_ShadowName[0] != '\0'
Note over PS: Check fails (empty string)
PS->>PS: Uses default texture name instead
PS-->>Code: Success! Shadow created safely
|
Perhaps there should be a default constructor for |
Good thinking. Updated! |
|
Does this tend to only get hit under mod use? |
Closes #2214
This change fixes a crash caused by spawning a
CreateDebrisobject with an assignedShadowby initializing the shadow name to an empty string.When the shadow name is uninitialized, checks for
'\0'andstrlen <= 1fail and garbage data is instead passed to various locations that do not expect it nor know how to deal with it.