-
Notifications
You must be signed in to change notification settings - Fork 117
fix: Replace strncpy with strlcpy for robustness #1533
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
Conversation
GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp
Show resolved
Hide resolved
1b26f0d to
863e100
Compare
|
"Partially resolves" means merging this change will close the issue. |
xezon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs another pass. strncpy was not correctly substituted at many places.
863e100 to
b035767
Compare
|
The Replay Checker crashes with this: |
b035767 to
1c95020
Compare
1c95020 to
a7561fd
Compare
xezon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the lengths need another review pass.
18edc27 to
bad3f0f
Compare
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp
Outdated
Show resolved
Hide resolved
bad3f0f to
606f5d1
Compare
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp
Outdated
Show resolved
Hide resolved
| nameLen=strlen(shadowInfo->m_ShadowName); | ||
| if (nameLen <= 1) //no texture name given, use same as object | ||
| { strcpy(texture_name,defaultDecalName); | ||
| if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect we can simplify this to if (shadowInfo->m_ShadowName[0] == '\0') without any change in functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand C-strings correctly:
m_ShadowName[0] = 'a';
m_ShadowName[1] = '\0';This represents a string of length 1. In that case, strlen(m_ShadowName) returns 1, so the original condition strlen(...) <= 1 would evaluate to true.
The null terminator is at index [1], not [0]. So checking only m_ShadowName[0] == '\0' is not equivalent — it would only detect the empty string (""), not a one-character string.
So at the moment the game does not allow texture names of 1 character. I don't know if that is intentional, or that this comparison is bugged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is odd comparison. One would expect strlen(shadowInfo->m_ShadowName) == 0 or strlen(shadowInfo->m_ShadowName) < 1. I suspect that was the intention.
You can run the game with a break point for if (strlen(shadowInfo->m_ShadowName) == 1) and see if that ever hits. If it never hits, I do not think we need to care for it.
|
Looks shadow decal related |
5c11d68 to
bd1b0e8
Compare
|
Made another pass
Game looks and runs well. I think this is (finally) it. |
|
Is this fully replicated in Generals? |
Yes it is |

Uh oh!
There was an error while loading. Please reload this page.