Repository navigation
obdscanner: actually reject out-of-range CAN identifiers - #5313
Open
qianeric-backup wants to merge 1 commit into
Open
qianeric-backup wants to merge 1 commit into
qianeric-backup wants to merge 1 commit into
Conversation
The range check used a chained comparison (`0 > source >= 0x800`), which is always false, so out-of-range ids were accepted and silently sent as 29-bit extended identifiers. The scan then finished with exit status 0 and no data. AI-Assisted: yes (DeepSeek agent)
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.
What
obdscannerdocuments--source/--destinationas 11-bit CAN identifiers (0x000–0x7ff) and already contains the check for it, but that check can never fire: it is written as the chained comparison0 > source >= 0x800, which expands to0 > source and source >= 0x800and is always false. Only the third operand (source == destination) of the sameifstatement works.Why
Out-of-range identifiers are accepted silently and the scan "succeeds":
A capture on vcan0 shows the frames are really transmitted as 29-bit extended identifiers (
scapy/contrib/automotive/isotp_native_socket.pysetsCAN_EFF_FLAGfortx_id > 0x7ff), so no OBD ECU will ever answer and the user gets a zero-exit "no data" scan instead of a diagnostic:--source0x800(invalid)id=0x800 flags=extended len=160x7e0(valid)id=0x7e0 flags= len=16Without a CAN interface the invalid id is reported as a missing device (
Socket couldn't be created. Check your arguments./[Errno 19] No such device), which points at the wrong problem.Clean sibling
In the same function, the sibling checks already behave correctly and print a single line with a non-zero exit code, which is what this
ifwas meant to do:--source 0x7e0 --destination 0x7e0(third operand)The ids must be >= 0 and < 0x800 and not equal.--timeout -5(adjacent range check)The timeout must be a positive value--source 0x800 --destination 0x7dfChange
Make the two range predicates real comparisons; the existing message, exit code and control flow are unchanged:
No behaviour change for valid identifiers, and no new user-visible strings.
Test
Two subprocess tests added to
test/tools/obdscanner.uts(+ Usage tests, next to the existing usage tests), covering an out-of-range source and an out-of-range destination id:On master the same two tests fail (
assert returncode != 0→ the scan exits 0).tox -e flake8is clean on both trees (0 findings).Before / after
--channel vcan0,-t 0.01 -1unless noted)--source 0x800 --destination 0x7dfNo data to displayThe ids must be >= 0 and < 0x800 and not equal.--source 0x7e0 --destination 0x800--source 0x7e0 --destination 0x7e0--source 0x7e0 --destination 0x7df--timeout -5The timeout must be a positive value--channel can0 --source 0x800 …(no device)[Errno 19] No such deviceFull-suite comparison
220
.utsfiles run per tree. The only differences between the two runs were port-contention flakes indoip.uts,tlsclientserver.utsandp0f.utsthat reproduce on the patched tree when run alone (0 failures), i.e. no test passes on master and fails with this patch.AI-Assisted: yes (DeepSeek agent)