pytest: fix channeld_fakenet divide by zero bug.
What changed, and why it matters
This commit fixes a divide-by-zero bug and a logic error in a fake network plugin used only during testing. The affected code is not part of the production Core Lightning software, so real users are not at risk. The bug could crash the test plugin if a certain parameter was zero, and a separate logic error meant ranges with non-zero minimums were computed incorrectly.
No production action needed; ensure test suite includes coverage for edge cases such as max == min or max == 0 in channel_range().
Security signals we found
divide-by-zero / SIGFPE in test-only plugin
incorrect range-scaling logic when min != 0
fix located in tests/plugins/ directory (non-production)
Evidence from the diff
In tests/plugins/channeld_fakenet.c, channel_range() computed min + (hash % max). If max was 0, the modulo operation caused a SIGFPE crash. Additionally, the modulo should have been (max - min) to correctly scale the hash into the [min, max) range. The patch adds an assert(max != min) and changes the modulo to (max - min). The only production caller is updated from max=900 to max=900 with min=1, then a second call uses the result as max with min=0, so the assert holds. The file is a pytest plugin, not production code.
Changed components
tests/plugins/channeld_fakenet.cInspect captured patch +3 / −2
diff --git a/tests/plugins/channeld_fakenet.c b/tests/plugins/channeld_fakenet.c
index 7714b9d7..dd1d318c 100644
--- a/tests/plugins/channeld_fakenet.c
+++ b/tests/plugins/channeld_fakenet.c
@@ -132,7 +132,8 @@ static u64 channel_range(const struct info *info,
const struct short_channel_id_dir *scidd,
u64 min, u64 max)
{
- return min + (siphash24(&info->seed, scidd, sizeof(scidd)) % max);
+ assert(max != min);
+ return min + (siphash24(&info->seed, scidd, sizeof(scidd)) % (max - min));
}
void ecdh(const struct pubkey *point, struct secret *ss)
@@ -840,7 +841,7 @@ found_next:
dfwd->expected = next;
/* Delay 0.1 - 1 seconds, but skewed lower */
- msec_delay = channel_range(info, &scidd, 0, 900);
+ msec_delay = channel_range(info, &scidd, 1, 900);
msec_delay = 100 + channel_range(info, &scidd, 0, msec_delay);
status_debug("Delaying %u msec for %s",
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.