Skip to content

Avoid buffer overflow for small Basic Authentication header #841

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

Merged
merged 1 commit into from
Aug 19, 2023

Conversation

matth-x
Copy link
Contributor

@matth-x matth-x commented Aug 19, 2023

This PR fixes a crash which occurs for small input lengths of the base64_encode function.

For a very small auth (length < 3), the base64_encode function fails when reaching the following line:

https://github.com/Links2004/arduinoWebSockets/blob/751cf87b6cd684c9d339f0314a18b0ee866d449c/src/WebSockets.cpp#L582C22-L582C22

This is the error message on the console:

CORRUPT HEAP: Bad tail at 0x3ffbdb1c. Expected 0xbaad5678 got 0xbaad5600

assert failed: multi_heap_free multi_heap_poisoning.c:253 (head != NULL)

Probably it is due to a buffer overflow. With a minimum buffer size of 5, this crash doesn't occur anymore.

To test the fix, I called WebSocketsClient::setAuthorization(const char * user, const char * password) with user "" and password "b".

Btw. and thanks for providing this library. I've been using it for years now and always enjoyed working with it.

@Links2004 Links2004 merged commit 30d5e13 into Links2004:master Aug 19, 2023
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