From 55000a71c9847e79f9e39d3815d109984b68b44b Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Thu, 20 Mar 2008 23:58:27 +0000 Subject: [PATCH] Do not accept strings like 0.0.0.0.0 as IP masks. (Reported by the Quakenet crew: paulr, splidge, and company.) git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1872 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ChangeLog | 9 +++++++++ ircd/ircd_string.c | 4 +++- ircd/test/ircd_in_addr_t.c | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37007c7..8f1e198 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-03-20 Michael Poole + + * ircd/ircd_string.c (ircd_aton_ip4): Reject strings with more + than 3 dots in them. + + * ircd/test/ircd_in_addr_t.c (test_addrs): Update the expected + parsing for a bare IPv4 address to a IPv4-mapped address. + (test_masks): Add a test for the ircd_string.c change. + 2008-03-20 Kevin L. Mitchell * include/client.h: IsLocOp() now checks to see if its MyUser() as diff --git a/ircd/ircd_string.c b/ircd/ircd_string.c index 1ed082d..b5b32cf 100644 --- a/ircd/ircd_string.c +++ b/ircd/ircd_string.c @@ -481,9 +481,11 @@ ircd_aton_ip4(const char *input, unsigned int *output, unsigned char *pbits) *pbits = bits; return pos; case '.': + if (++dots > 3) + return 0; if (input[++pos] == '.') return 0; - ip |= part << (24 - 8 * dots++); + ip |= part << (32 - 8 * dots); part = 0; if (input[pos] == '*') { while (input[++pos] == '*' || input[pos] == '.') ; diff --git a/ircd/test/ircd_in_addr_t.c b/ircd/test/ircd_in_addr_t.c index 1a65aec..7eaf56e 100644 --- a/ircd/test/ircd_in_addr_t.c +++ b/ircd/test/ircd_in_addr_t.c @@ -29,7 +29,7 @@ static struct address_test test_addrs[] = { {{ 0, 0, 0, 0, 0, 0, 0, 1 }}, "AAAAAA", "_AAB", 1, 0, 1 }, { "127.0.0.1", "127.0.0.1", - {{ 0, 0, 0, 0, 0, 0, 0x7f00, 1 }}, + {{ 0, 0, 0, 0, 0, 0xffff, 0x7f00, 1 }}, "B]AAAB", "B]AAAB", 1, 1, 1 }, { "::ffff:127.0.0.3", "127.0.0.3", {{ 0, 0, 0, 0, 0, 0xffff, 0x7f00, 3 }}, @@ -123,6 +123,7 @@ static struct ipmask_test test_masks[] = { { "a:*", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 }, { "a:*:*", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 }, { "a:/16", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 }, + { "0.0.0.0.0/1", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0, 0, 0 }, { 0 } }; -- 2.20.1