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

Avoid buffer overflow in Log. #829

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

f1rmb
Copy link
Contributor

@f1rmb f1rmb commented Mar 4, 2025

Avoid possible buffer overflow.
Fix instant crashing when compiled and run on LinuxMint (GCC 13.3) and probably many distro with recent toolchain. It seems I'm not the only one experiencing this problem:

*** buffer overflow detected ***: terminated
Aborted (core dumped)

It's identical to #811.

@g4klx
Copy link
Owner

g4klx commented Mar 7, 2025

Before I make changes, I want to know what log message is causing this error. I don't normally generate long log messages, so what is it trying to log? Please show me.

@f1rmb
Copy link
Contributor Author

f1rmb commented Mar 7, 2025

It's not a matter of log message, it's purely a possible buffer overflow, handled at run time.

::vsnprintf(buffer + ::strlen(buffer), 500, fmt, vl);

is wrong, as passed buffer is NOT &buffer[0], but &buffer[::strlen(buffer)], hence the vsnprintf max length argument is overflowing the buffer by ::strlen(buffer).

Older GCC and libs don't check for this bug, new ones does.

@f1rmb
Copy link
Contributor Author

f1rmb commented Mar 7, 2025

Also, when compiled with my GCC 13, the code abort() before any logging message is displayed/logged, as that happens when vsnprintf() is called.

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

Successfully merging this pull request may close these issues.

2 participants