pytest: fix channeld_fakenet divide by zero bug.

1. If max was 0, we crashed with SIGFPE due to % 0.
2. If min was non-zero, logic was incorrect (but all callers had min == 0).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2026-02-04 14:14:38 +10:30
parent 13545124eb
commit 23202b7e85

View File

@@ -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",