Only skip .0 address if the pool is big enough.
ok patrick@
-/* $OpenBSD: ikev2.c,v 1.320 2021/05/13 15:20:48 tobhe Exp $ */
+/* $OpenBSD: ikev2.c,v 1.321 2021/05/31 16:54:45 tobhe Exp $ */
/*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
return (-1);
}
- if (lower == 0)
- lower = 1;
/* Note that start, upper and host are in HOST byte order */
upper = ntohl(~mask);
+ /* skip .0 address if possible */
+ if (lower < upper && lower == 0)
+ lower = 1;
+ if (upper < lower)
+ upper = lower;
/* Randomly select start from [lower, upper-1] */
start = arc4random_uniform(upper - lower) + lower;