commit: 97b3c5bd2e165988bc0f042f9e1d7bbf077b0320
parent 7e1203f36d86742147600cd7fbca141a07df32e4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 19 Oct 2025 02:25:15 +0200
fix infinite loop when end is 255.255.255.255
Diffstat:
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/cidr2list.c b/cidr2list.c
@@ -150,10 +150,21 @@ main(void)
fprintf(stderr, "%d.%d.%d.%d\n", (end >> 24) & 0xFF, (end >> 16) & 0xFF, (end >> 8) & 0xFF, end & 0xFF);
#endif
+ bool frontier = false;
+ if(end == 0xFFFFFFFFUL)
+ {
+ // Otherwise for-loop overflows and goes loopy due to
+ // the `<=` comparison which works for all other cases
+ end--;
+ frontier = true;
+ }
+
for(uint32_t ai = start; ai <= end; ai++)
{
printf("%d.%d.%d.%d\n", (ai >> 24) & 0xFF, (ai >> 16) & 0xFF, (ai >> 8) & 0xFF, ai & 0xFF);
}
+
+ if(frontier) puts("255.255.255.255");
}
free(buf);
diff --git a/test.sh b/test.sh
@@ -2,7 +2,7 @@
# Copyright © 2025 Haelwenn (lanodan) Monnier <contact+utils-cidr@hacktivis.me>
# SPDX-License-Identifier: MPL-2.0
-plans=10
+plans=11
WD=$(dirname "$0")
target="${WD}/cidr2list"
. ./tap.sh
@@ -29,4 +29,8 @@ t --input='192.168.0.43/31' 192.168.0.43/31 '192.168.0.42
t --input=192.168.0.42 nocidr '192.168.0.42
'
+t --input=255.255.255.254/31 no_overflow:255.255.255.254/31 '255.255.255.254
+255.255.255.255
+'
+
t_cmd empty_lines 4 lines ' ' 192.168.0.42/31 ' ' 192.168.0.69/31 ''