Skip to content
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

Hud saytext message handling can cause buffer overflow #3095

Open
SamVanheer opened this issue Apr 14, 2021 · 0 comments
Open

Hud saytext message handling can cause buffer overflow #3095

SamVanheer opened this issue Apr 14, 2021 · 0 comments

Comments

@SamVanheer
Copy link

The Hud's saytext message handling can cause a buffer overflow here:

strncpy( g_szLineBuffer[i], pszBuf, max(iBufSize , MAX_CHARS_PER_LINE) );

This copies the incoming text into a buffer. The maximum number of characters is calculated as the greater of the buffer size and the size of the incoming text. This means a sufficiently large piece of text would overflow the buffer.

In practice this will never happen because the maximum size that a user message can be is smaller than the buffer size (192 bytes vs 256), but if that size were ever increased it could become an issue.

To fix this, the code needs to be changed to:

strncpy( g_szLineBuffer[i], pszBuf, min(iBufSize , MAX_CHARS_PER_LINE) );

Though it's probably fine to remove the use of min altogether and just passing MAX_CHARS_PER_LINE instead along with null terminating the buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant