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

Resolve issue #832 (Potential memory corruption) #835

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

Conversation

arjenhiemstra
Copy link

The memmove command is executed without any sanity checking on used values causing random reboots when an MQTT package gets processed with an impossible topic length.
With a high rate test flow of MQTT messages this would sometimes corrupt memory after a few seconds.

Extra sanity checks and calculation for payload_offset and message length have been implemented to better handle messages and prevent this memory corruption.

Tested with a flow of about 50.000 messages per hour for multiple days. Went from hundreds of errors per hour to a few per day, the last errors mainly because the MQTT server couldn't keep up with the message flow. Never crashed again.
A big thanks to @TD-er for help with further refactoring the code.

The memmove command is executed without any sanity checking on used values causing random reboots when an MQTT package gets processed with an impossible topic length.
With a high rate test flow of MQTT messages this would sometimes corrupt memory after a few seconds.

Extra sanity checks and calculation for payload_offset and message length have been implemented to better handle messages and prevent this memory corruption.

Tested with a flow of about 50.000 messages per hour for multiple days. Went from hunderds of errors per hour til a few per day, the last errors mainly because the MQTT server couldn't keep up with the message flow. Never crashed again.
@@ -368,7 +368,7 @@ uint32_t PubSubClient::readPacket(uint8_t* lengthLength) {
}

boolean PubSubClient::loop_read() {
if (_client == nullptr) {
if (_client == NULL) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do this change?
NULL is not a pointer type, so the compiler cannot help you here to check for wrong usage.
nullptr is a pointer type, so it is an improvement over the old NULL

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because otherwise the travis ci build behind the repo doesn't run

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's strange.
What kind of compiler or compiler settings is used?

Copy link
Author

@arjenhiemstra arjenhiemstra Feb 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you click on 'details' behind "continuous-integration/travis-ci/pr — The Travis CI build failed"
you see all the build system info

@technyon
Copy link

Any update on this PR? It it going to get merged?

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.

3 participants