From 4eec8b3824d49c1c0503ebbf7844a4e312bc29e1 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu" Date: Thu, 13 Nov 2008 09:36:37 +0000 Subject: 2.4.4 - Premature checking prevents to add valid elements to hash types, fixed (bug reported by JC Janos). - Local variable shadows another variable, fixed (reported by Jan Engelhardt). - More compiler warning options added and warnings fixed. --- kernel/ip_set_nethash.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'kernel/ip_set_nethash.c') diff --git a/kernel/ip_set_nethash.c b/kernel/ip_set_nethash.c index 9b3d826..d5b7a76 100644 --- a/kernel/ip_set_nethash.c +++ b/kernel/ip_set_nethash.c @@ -35,6 +35,8 @@ nethash_id_cidr(const struct ip_set_nethash *map, ip_set_ip_t *elem; *hash_ip = pack_ip_cidr(ip, cidr); + if (!*hash_ip) + return MAX_RANGE; for (i = 0; i < map->probes; i++) { id = jhash_ip(map, i, *hash_ip) % map->hashsize; @@ -67,13 +69,13 @@ nethash_test_cidr(struct ip_set *set, ip_set_ip_t *hash_ip, { const struct ip_set_nethash *map = set->data; - return (ip && nethash_id_cidr(map, hash_ip, ip, cidr) != UINT_MAX); + return (nethash_id_cidr(map, hash_ip, ip, cidr) != UINT_MAX); } static inline int nethash_test(struct ip_set *set, ip_set_ip_t *hash_ip, ip_set_ip_t ip) { - return (ip && nethash_id(set, hash_ip, ip) != UINT_MAX); + return (nethash_id(set, hash_ip, ip) != UINT_MAX); } static int @@ -120,15 +122,15 @@ nethash_add(struct ip_set *set, ip_set_ip_t *hash_ip, struct ip_set_nethash *map = set->data; int ret; - if (!ip || map->elements >= limit) - return -ERANGE; + if (map->elements >= limit || map->nets[cidr-1] == UINT16_MAX) + return -ERANGE; if (cidr <= 0 || cidr >= 32) return -EINVAL; - if (map->nets[cidr-1] == UINT16_MAX) - return -ERANGE; - + *hash_ip = pack_ip_cidr(ip, cidr); DP("%u.%u.%u.%u/%u, %u.%u.%u.%u", HIPQUAD(ip), cidr, HIPQUAD(*hash_ip)); + if (!*hash_ip) + return -ERANGE; ret = __nethash_add(map, hash_ip); if (ret == 0) { @@ -164,8 +166,6 @@ nethash_del(struct ip_set *set, ip_set_ip_t *hash_ip, struct ip_set_nethash *map = set->data; ip_set_ip_t id, *elem; - if (!ip) - return -ERANGE; if (cidr <= 0 || cidr >= 32) return -EINVAL; -- cgit v1.2.3