diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-01-06 16:59:33 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-01-06 16:59:33 +0000 |
commit | 02c5329cc042d2f58a0af8920888f29d41c43c7b (patch) | |
tree | 1621bc3dda8b084dbc557c31586f343e2bdea011 /src/util.c | |
parent | 3acedc39adb56990a6241936814938afaf96b8bb (diff) | |
download | rspamd-02c5329cc042d2f58a0af8920888f29d41c43c7b.tar.gz rspamd-02c5329cc042d2f58a0af8920888f29d41c43c7b.zip |
Validate IP addresses before pushing them to lua.
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 776e807d1..14af4b2bd 100644 --- a/src/util.c +++ b/src/util.c @@ -2440,6 +2440,29 @@ rspamd_prng_seed (void) g_random_set_seed (rand_seed); } +gboolean +rspamd_ip_is_valid (void *ptr, int af) +{ + const struct in_addr ip4_any = { INADDR_ANY }, ip4_none = { INADDR_NONE }; + const struct in6_addr ip6_any = IN6ADDR_ANY_INIT; + + gboolean ret = FALSE; + + if (G_LIKELY (af == AF_INET)) { + if (memcmp (ptr, &ip4_any, sizeof (struct in_addr)) != 0 && + memcmp (ptr, &ip4_none, sizeof (struct in_addr)) != 0) { + ret = TRUE; + } + } + else if (G_UNLIKELY (af == AF_INET6)) { + if (memcmp (ptr, &ip6_any, sizeof (struct in6_addr)) != 0) { + ret = TRUE; + } + } + + return ret; +} + /* * vi:ts=4 */ |