Reject binary trace routes that exceed representable hop count
This commit is contained in:
1 parent
f65a8269f3
commit
ebc103f085
3 files changed
+142
-9
No files matched your search
@@ -16,7 +16,7 @@ FIXTURE = ROOT / "test/fixtures/trace_profile_timing.cpp"
|
||||
|
||||
|
||||
class TraceProfileTimingTests(unittest.TestCase):
|
||||
def run_fixture(self, mutation=None):
|
||||
def run_fixture(self, mutation=None, scenario=None):
|
||||
companion = (ROOT / "examples/companion_radio/MyMesh.cpp").read_text()
|
||||
dispatcher = (ROOT / "src/Dispatcher.cpp").read_text()
|
||||
mesh = (ROOT / "src/Mesh.cpp").read_text()
|
||||
@@ -33,6 +33,10 @@ class TraceProfileTimingTests(unittest.TestCase):
|
||||
methods += extract_braced(dispatcher, signature) + "\n"
|
||||
for signature in ("Packet* Mesh::createTrace(", "bool Mesh::sendDirect("):
|
||||
methods += extract_braced(mesh, signature) + "\n"
|
||||
trace_receive = extract_braced(mesh,
|
||||
"if (pkt->isRouteDirect() && pkt->getPayloadType() == PAYLOAD_TYPE_TRACE)")
|
||||
methods += "uint32_t Mesh::receiveTrace(Packet* pkt) {\n" + trace_receive
|
||||
methods += "\nreturn ACTION_RELEASE;\n}\n"
|
||||
methods += "}\n" + extract_braced(driver, "uint32_t RadioLibWrapper::getProfileAirtime(") + "\n"
|
||||
terminal = extract_braced(companion, "void MyMesh::sendTerminalTraceRoute(")
|
||||
binary = extract_braced(companion, "} else if (cmd_frame[0] == CMD_SEND_TRACE_PATH")
|
||||
@@ -52,6 +56,10 @@ class TraceProfileTimingTests(unittest.TestCase):
|
||||
work = Path(directory)
|
||||
(work / "production.inc").write_text(methods, encoding="ascii")
|
||||
(work / "constants.inc").write_text(constants, encoding="ascii")
|
||||
(work / "trace_priority.inc").write_text("\n".join(extract_braced(mesh, signature)
|
||||
for signature in ("static uint8_t decodeTraceHashSize(",
|
||||
"static uint8_t getTraceRemainingHops(",
|
||||
"static uint8_t getTraceDirectPriority(")), encoding="ascii")
|
||||
binary_path = work / "trace"
|
||||
sanitizers = (["-fsanitize=address,undefined", "-fno-sanitize-recover=all",
|
||||
"-fno-pie", "-no-pie"] if sys.platform.startswith("linux") else [])
|
||||
@@ -62,7 +70,27 @@ class TraceProfileTimingTests(unittest.TestCase):
|
||||
str(ROOT / "src/helpers/CompanionDelayedReplies.cpp"), "-o", str(binary_path)],
|
||||
capture_output=True, text=True, timeout=60)
|
||||
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
|
||||
return subprocess.run([str(binary_path)], capture_output=True, text=True, timeout=20)
|
||||
return subprocess.run([str(binary_path)] + ([scenario] if scenario else []),
|
||||
capture_output=True, text=True, timeout=20)
|
||||
|
||||
def test_binary_hop_boundary_rejects_64_before_side_effects_and_63_completes(self):
|
||||
result = self.run_fixture(scenario="hop-boundary")
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertIn("PASS: 63-hop traces complete and 64-hop commands have no side effects", result.stdout)
|
||||
|
||||
def test_exact_old_64_hop_admission_cannot_complete_and_wraps_timeout(self):
|
||||
def old(terminal, binary):
|
||||
changed, count = re.subn(r"\(path_len >> path_sz\) >= MAX_PATH_SIZE",
|
||||
"(path_len >> path_sz) > MAX_PATH_SIZE", binary)
|
||||
self.assertEqual(count, 1)
|
||||
return terminal, changed
|
||||
for hash_size in (1, 2):
|
||||
with self.subTest(hash_size=hash_size):
|
||||
result = self.run_fixture(old, "hop-boundary-" + str(hash_size))
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("old 64-hop admission hash=" + str(hash_size), result.stderr)
|
||||
self.assertIn("64-hop trace must be rejected: admitted route cannot complete and timeout count wraps",
|
||||
result.stderr)
|
||||
|
||||
def test_actual_trace_producers_mask_admission_and_complete_wire_length(self):
|
||||
result = self.run_fixture()
|
||||
|
||||
Reference in new issue
Block a user