aboutsummaryrefslogtreecommitdiffstats
path: root/src/map.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-09-03 13:59:12 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-09-03 13:59:12 +0400
commitc9d98a8fc24f76d979ad479eff2fa66b31703832 (patch)
tree3e7da89081fd35425db582dacbdd3277adf40aaf /src/map.c
parent563a106f3a57e460b9c5ea06a2eb4e6456f9e080 (diff)
downloadrspamd-c9d98a8fc24f76d979ad479eff2fa66b31703832.tar.gz
rspamd-c9d98a8fc24f76d979ad479eff2fa66b31703832.zip
* Various bugfixes in map and radix code
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/src/map.c b/src/map.c
index 0202f448f..f19b822b6 100644
--- a/src/map.c
+++ b/src/map.c
@@ -317,7 +317,7 @@ add_map (const char *map_line, map_cb_t read_callback, map_fin_cb_t fin_callback
def = map_line + sizeof ("file://") - 1;
}
else {
- msg_err ("add_map: invalid map fetching protocol: %s", map_line);
+ msg_debug ("add_map: invalid map fetching protocol: %s", map_line);
return FALSE;
}
/* Constant pool */
@@ -419,7 +419,7 @@ abstract_parse_list (memory_pool_t *pool, u_char *chunk, size_t len, struct map_
if (*p == '#') {
if (s != str) {
*s = '\0';
- s = memory_pool_strdup (pool, str);
+ s = memory_pool_strdup (pool, g_strstrip (str));
if (strlen (s) > 0) {
func (data->cur_data, s, hash_fill);
}
@@ -431,7 +431,7 @@ abstract_parse_list (memory_pool_t *pool, u_char *chunk, size_t len, struct map_
else if (*p == '\r' || *p == '\n') {
if (s != str) {
*s = '\0';
- s = memory_pool_strdup (pool, str);
+ s = memory_pool_strdup (pool, g_strstrip (str));
if (strlen (s) > 0) {
func (data->cur_data, s, hash_fill);
}
@@ -442,9 +442,6 @@ abstract_parse_list (memory_pool_t *pool, u_char *chunk, size_t len, struct map_
p ++;
}
}
- else if (g_ascii_isspace (*p)) {
- p ++;
- }
else {
*s = *p;
s ++;
@@ -480,38 +477,52 @@ radix_tree_insert_helper (gpointer st, gconstpointer key, gpointer value)
uint32_t mask = 0xFFFFFFFF;
uint32_t ip;
- char *token, *ipnet;
+ char *token, *ipnet, *err_str, **strv, **cur;
struct in_addr ina;
int k;
- k = strlen ((char *)key) + 1;
- ipnet = alloca (k);
- g_strlcpy (ipnet, key, k);
- token = strsep (&ipnet, "/");
-
- if (ipnet != NULL) {
- k = atoi (ipnet);
- if (k > 32 || k < 0) {
- msg_warn ("radix_tree_insert_helper: invalid netmask value: %d", k);
- k = 32;
+ strv = g_strsplit_set ((char *)key, " ,;", 0);
+ cur = strv;
+ while (*cur) {
+ if (**cur == '\0') {
+ cur ++;
+ continue;
+ }
+ ipnet = *cur;
+ token = strsep (&ipnet, "/");
+
+ if (ipnet != NULL) {
+ errno = 0;
+ k = strtoul (ipnet, &err_str, 10);
+ if (errno != 0) {
+ msg_warn ("radix_tree_insert_helper: invalid netmask, error detected on symbol: %s, erorr: %s", err_str, strerror (errno));
+ k = 32;
+ }
+ else if (k > 32 || k < 0) {
+ msg_warn ("radix_tree_insert_helper: invalid netmask value: %d", k);
+ k = 32;
+ }
+ k = 32 - k;
+ mask = mask << k;
}
- k = 32 - k;
- mask = mask << k;
- }
- if (inet_aton (token, &ina) == 0) {
- msg_err ("radix_tree_insert_helper: invalid ip address: %s", token);
- return;
- }
+ if (inet_aton (token, &ina) == 0) {
+ msg_err ("radix_tree_insert_helper: invalid ip address: %s", token);
+ return;
+ }
- ip = ntohl ((uint32_t)ina.s_addr);
- k = radix32tree_insert (tree, ip, mask, 1);
- if (k == -1) {
- msg_warn ("radix_tree_insert_helper: cannot insert ip to tree: %s, mask %X", inet_ntoa (ina), mask);
- }
- else if (k == 1) {
- msg_warn ("add_ip_radix: ip %s, mask %X, value already exists", inet_ntoa (ina), mask);
+ ip = ntohl ((uint32_t)ina.s_addr);
+ k = radix32tree_insert (tree, ip, mask, 1);
+ if (k == -1) {
+ msg_warn ("radix_tree_insert_helper: cannot insert ip to tree: %s, mask %X", inet_ntoa (ina), mask);
+ }
+ else if (k == 1) {
+ msg_warn ("add_ip_radix: ip %s, mask %X, value already exists", inet_ntoa (ina), mask);
+ }
+ cur ++;
}
+
+ g_strfreev (strv);
}
u_char *