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