From 2157a301924bafccc260280d46ddc9bc30152f08 Mon Sep 17 00:00:00 2001 From: DanS Date: Sun, 19 Jul 2026 13:39:04 -0500 Subject: [PATCH] fix(tests): guard updater asset-selection index reads against OOB testXmrigAssetSelection / testDaemonAssetSelection index rel.assets[i] right after EXPECT_TRUE(i >= 0), but select*Asset returns -1 on no match and this harness's EXPECT doesn't abort -- so a fixture/parser regression would read rel.assets[-1] and SIGSEGV the whole suite instead of reporting the failed EXPECT. Gate each index read behind `if (i >= 0)` (same pattern as the AddressBook config-dir fix). No behavior change on the valid checked-in fixtures; ctest passes 100%. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/test_phase4.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_phase4.cpp b/tests/test_phase4.cpp index f355501..22727fb 100644 --- a/tests/test_phase4.cpp +++ b/tests/test_phase4.cpp @@ -5300,8 +5300,11 @@ void testXmrigAssetSelection() EXPECT_TRUE(linux >= 0); EXPECT_TRUE(win >= 0); EXPECT_TRUE(linux != win); - EXPECT_TRUE(rel.assets[linux].name.find("linux-x64.zip") != std::string::npos); - EXPECT_TRUE(rel.assets[win].name.find("win-x64.zip") != std::string::npos); + // Guard the index reads: select*Asset returns -1 when nothing matches, and EXPECT_TRUE doesn't + // abort this harness, so an unguarded rel.assets[-1] on a fixture/parser regression would SIGSEGV + // the whole suite instead of reporting the failed EXPECT above. + if (linux >= 0) EXPECT_TRUE(rel.assets[linux].name.find("linux-x64.zip") != std::string::npos); + if (win >= 0) EXPECT_TRUE(rel.assets[win].name.find("win-x64.zip") != std::string::npos); // No macOS build in this fixture -> graceful "not found". EXPECT_EQ(selectXmrigAsset(rel, "macos-x86_64"), -1); EXPECT_EQ(selectXmrigAsset(rel, "macos-arm64"), -1); @@ -5607,9 +5610,11 @@ void testDaemonAssetSelection() const int win = selectDaemonAsset(rel, "win64"); EXPECT_TRUE(lin >= 0 && mac >= 0 && win >= 0); EXPECT_TRUE(lin != mac && mac != win && lin != win); - EXPECT_TRUE(rel.assets[lin].name.find("linux-amd64.zip") != std::string::npos); - EXPECT_TRUE(rel.assets[mac].name.find("macos.zip") != std::string::npos); - EXPECT_TRUE(rel.assets[win].name.find("win64.zip") != std::string::npos); + // Guard the index reads (select*Asset returns -1 on no match; EXPECT_TRUE doesn't abort here) so a + // fixture/parser regression reports the failed EXPECT above instead of an OOB rel.assets[-1] crash. + if (lin >= 0) EXPECT_TRUE(rel.assets[lin].name.find("linux-amd64.zip") != std::string::npos); + if (mac >= 0) EXPECT_TRUE(rel.assets[mac].name.find("macos.zip") != std::string::npos); + if (win >= 0) EXPECT_TRUE(rel.assets[win].name.find("win64.zip") != std::string::npos); // Wrong/foreign tokens (e.g. the miner's naming) must NOT match the daemon archives. EXPECT_EQ(selectDaemonAsset(rel, "linux-x64"), -1); EXPECT_EQ(selectDaemonAsset(rel, "linux-arm64"), -1);