-
Notifications
You must be signed in to change notification settings - Fork 117
fix: Replace strcat with strlcat for robustness #1685
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
fix: Replace strcat with strlcat for robustness #1685
Conversation
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.
Note that strlcpy, strlcat will have a tiny computational overhead over strcpy, strcat, for the benefit of stability. When touching hot code, such as AsciiString, UnicodeString, be extra mindful about it.
Generally, prefer using ARRAY_SIZE(buffer) instead of sizeof(buffer) or BUFFER_SIZE_VALUE. Because ARRAY_SIZE(buffer) works for both char* and wchar_t* and adapts without touching when the actual buffer changes.
Examples:
wchar_t buffer[123];
wcslcpy(buffer, src, sizeof(buffer)); // <---- wrong! sizeof(buffer) is too large and allows buffer overflow: better ARRAY_SIZE(buffer)char buffer[MAX_PATH];
strlcpy(buffer, src, MAX_PATH); // <---- correct, but needs to be kept in sync with declaration: better ARRAY_SIZE(buffer)073cb7f to
02fdae5
Compare
|
I don't understand why it doesn't compile VC6. Works fine on my PC. |
|
Try change |
415e947 to
0537c28
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.
Needs to be replicated to Generals.
No understanding why this occurs, but this fixes it.
|
Rebased and replicated in generals |
0537c28 to
14e6641
Compare
This change replaces strcat with strlcat for robustness
TODO