Guard getNode() NULL result in set() and operator[] - #69
Open
tropicsquirrel wants to merge 1 commit into
Open
Conversation
… crash) getNode() reads AND writes a shared node cache (lastNodeGot / lastIndexGot / isCached) on every access. If two contexts (e.g. an ISR/RX-task producer and a main-loop consumer, as in ESP32Marauder's device lists) call into the list concurrently, that cache can be corrupted so getNode() walks off the end and returns NULL for an in-range index. set() and operator[] then dereferenced that NULL unconditionally (getNode(index)->data), crashing with a NULL write/read. get() already null-checks (returns T()), so only these two paths crash. Add the same guard: set() returns false, operator[] returns a static default-constructed fallback. No behavior change on the normal (non-corrupted) path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getNode()reads and writes a shared node cache (lastNodeGot/lastIndexGot/isCached) on every access, so concurrent access from two contexts can corrupt it and make it returnNULLfor an in-range index.set()andoperator[]then dereferenced that NULL unconditionally (getNode(index)->data) and crashed.get()already null-checks; this adds the same guard to the other two paths (set()returns false,operator[]returns a static default fallback). No change on the normal path.Found while auditing ESP32Marauder (which vendors this lib and calls it 'thread safe') for cross-task races.