Skip to content

probe: fix J-Link swo_read crash when swo_num_bytes() returns a negative value - #2021

Open
adityaanikam wants to merge 1 commit into
pyocd:mainfrom
adityaanikam:fix-jlink-swo-negative-count-2019
Open

probe: fix J-Link swo_read crash when swo_num_bytes() returns a negative value#2021
adityaanikam wants to merge 1 commit into
pyocd:mainfrom
adityaanikam:fix-jlink-swo-negative-count-2019

Conversation

@adityaanikam

Copy link
Copy Markdown

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.

…ive value

Signed-off-by: adityaanikam <adityanikam9502@gmail.com>
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.

J-Link SWVReader crashes when swo_num_bytes() returns a negative value

1 participant