-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: master
Are you sure you want to change the base?
Conversation
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) { |
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.
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
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.
Just because otherwise the travis ci build behind the repo doesn't run
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.
Hmm that's strange.
What kind of compiler or compiler settings is used?
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.
if you click on 'details' behind "continuous-integration/travis-ci/pr — The Travis CI build failed"
you see all the build system info
Any update on this PR? It it going to get merged? |
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.