summaryrefslogtreecommitdiffstats
path: root/kernel/ip_set_nethash.c
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu </C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu>2008-11-13 09:36:37 +0000
committer/C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu </C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu>2008-11-13 09:36:37 +0000
commit4eec8b3824d49c1c0503ebbf7844a4e312bc29e1 (patch)
tree9b67c7a33f683e5a607517dc3ca5a0ddaefeb449 /kernel/ip_set_nethash.c
parentb3259c8f91a689e01469b4eca8ada7924011be25 (diff)
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.
Diffstat (limited to 'kernel/ip_set_nethash.c')
-rw-r--r--kernel/ip_set_nethash.c18
1 files changed, 9 insertions, 9 deletions
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;