From 3e0aed77a51974b11ee86e889905ac57e9cdb756 Mon Sep 17 00:00:00 2001 From: QianEric Date: Thu, 26 Nov 2026 12:37:24 +0800 Subject: [PATCH] obdscanner: actually reject out-of-range CAN identifiers 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) --- scapy/tools/automotive/obdscanner.py | 2 +- test/tools/obdscanner.uts | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) mode change 100755 => 100644 scapy/tools/automotive/obdscanner.py diff --git a/scapy/tools/automotive/obdscanner.py b/scapy/tools/automotive/obdscanner.py old mode 100755 new mode 100644 index 5318fb82bf4..03bd312cf66 --- a/scapy/tools/automotive/obdscanner.py +++ b/scapy/tools/automotive/obdscanner.py @@ -172,7 +172,7 @@ def main(): file=sys.stderr) sys.exit(1) - if 0 > source >= 0x800 or 0 > destination >= 0x800\ + if not (0 <= source < 0x800) or not (0 <= destination < 0x800) \ or source == destination: print("The ids must be >= 0 and < 0x800 and not equal.", file=sys.stderr) diff --git a/test/tools/obdscanner.uts b/test/tools/obdscanner.uts index 1fe7ab31d26..c4bb47601f1 100644 --- a/test/tools/obdscanner.uts +++ b/test/tools/obdscanner.uts @@ -30,6 +30,34 @@ std_out, std_err = result.communicate() expected_output = plain_str(b'Scan for all possible obd service classes and their subfunctions.') assert expected_output in plain_str(std_out) + += Test out of range source id +result = subprocess.Popen([sys.executable, "scapy/tools/automotive/obdscanner.py", + "--interface", "socketcan", "--channel", "vcan0", + "--source", "0x800", + "--destination", "0x7df", "--timeout", "0.01", "-1"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) +returncode = result.wait() +std_out, std_err = result.communicate() +assert returncode != 0 + +expected_output = plain_str(b'The ids must be >= 0 and < 0x800 and not equal.') +assert expected_output in plain_str(std_err) + + += Test out of range destination id +result = subprocess.Popen([sys.executable, "scapy/tools/automotive/obdscanner.py", + "--interface", "socketcan", "--channel", "vcan0", + "--source", "0x7e0", + "--destination", "0x800", "--timeout", "0.01", "-1"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) +returncode = result.wait() +std_out, std_err = result.communicate() +assert returncode != 0 + +expected_output = plain_str(b'The ids must be >= 0 and < 0x800 and not equal.') +assert expected_output in plain_str(std_err) + + Scan tests = Load contribution layer