probe: fix J-Link swo_read crash when swo_num_bytes() returns a negative value - #2021
Open
adityaanikam wants to merge 1 commit into
Open
probe: fix J-Link swo_read crash when swo_num_bytes() returns a negative value#2021adityaanikam wants to merge 1 commit into
adityaanikam wants to merge 1 commit into
Conversation
…ive value Signed-off-by: adityaanikam <adityanikam9502@gmail.com>
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.
Fixes #2019.
JLinkProbe.swo_read() passed self._link.swo_num_bytes() straight into swo_read() as the count. pylink allocates a ctypes buffer sized to that count, so a negative value crashes with IndexError, which isn't a JLinkException and so isn't caught by the existing except clause either, it kills the SWV reader thread outright.
Guards the count before the call and returns an empty bytearray() when it's non-positive, matching DebugProbe.swo_read's documented return type, rather than the plain [] from the reporter's own tested monkey-patch.
No test added, JLinkProbe's constructor calls into the real J-Link DLL and raises ProbeError if it's not present, so testing this cleanly would mean bypassing normal construction in a way nothing else in this codebase does. Tested by reasoning through the exact reporter's traceback and pylink's ctypes buffer allocation, matching what they already confirmed works via their monkey-patch.