]> source.dussan.org Git - rspamd.git/commitdiff
Fix some more issues with fixed strings
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Oct 2015 13:24:06 +0000 (14:24 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Oct 2015 13:24:06 +0000 (14:24 +0100)
src/libserver/protocol.c
src/libutil/http.c

index 8b705814de0bcc23d990cfc249c473ca7c44bb4e..99a363166d52f65da31fa8874e338b55e810c5da 100644 (file)
@@ -263,7 +263,7 @@ rspamd_protocol_handle_url (struct rspamd_task *task,
                        value = v;
                        /* Steal strings */
                        g_hash_table_iter_steal (&it);
-                       g_hash_table_insert (task->request_headers, key, value);
+                       g_hash_table_replace (task->request_headers, key, value);
                }
 
                g_hash_table_unref (query_args);
@@ -299,7 +299,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                hn_tok = rspamd_ftok_map (hn);
                hv_tok = rspamd_ftok_map (hv);
 
-               g_hash_table_insert (task->request_headers, hn_tok, hv_tok);
+               g_hash_table_replace (task->request_headers, hn_tok, hv_tok);
 
                switch (*hn_tok->begin) {
                case 'd':
index 1dd22f309bca2446d8c7ac4af7568964859dd641..e082c3c24487bd4444f4cd71e343a357853bba9d 100644 (file)
@@ -2394,7 +2394,7 @@ rspamd_http_message_parse_query (struct rspamd_http_message *msg)
 {
        GHashTable *res;
        rspamd_fstring_t *key = NULL, *value = NULL;
-       rspamd_ftok_t *key_tok, *value_tok;
+       rspamd_ftok_t *key_tok = NULL, *value_tok = NULL;
        const gchar *p, *c, *end;
        struct http_parser_url u;
        enum {
@@ -2423,24 +2423,23 @@ rspamd_http_message_parse_query (struct rspamd_http_message *msg)
                                        if ((*p == '&' || p == end) && p > c) {
                                                /* We have a single parameter without a value */
                                                key = rspamd_fstring_new_init (c, p - c);
-                                               key_tok = g_slice_alloc (sizeof (*key_tok));
-                                               key_tok->begin = key->str;
+                                               key_tok = rspamd_ftok_map (key);
                                                key_tok->len = rspamd_decode_url (key->str, key->str,
                                                                key->len);
+
                                                value = rspamd_fstring_new_init ("", 0);
-                                               value_tok = g_slice_alloc (sizeof (*value_tok));
-                                               value_tok->begin = value->str;
-                                               value_tok->len = value->len;
-                                               g_hash_table_insert (res, key_tok, value_tok);
+                                               value_tok = rspamd_ftok_map (value);
+
+                                               g_hash_table_replace (res, key_tok, value_tok);
                                                state = parse_ampersand;
                                        }
                                        else if (*p == '=' && p > c) {
                                                /* We have something like key=value */
                                                key = rspamd_fstring_new_init (c, p - c);
-                                               key_tok = g_slice_alloc (sizeof (*key_tok));
-                                               key_tok->begin = key->str;
+                                               key_tok = rspamd_ftok_map (key);
                                                key_tok->len = rspamd_decode_url (key->str, key->str,
                                                                key->len);
+
                                                state = parse_eqsign;
                                        }
                                        else {
@@ -2463,21 +2462,19 @@ rspamd_http_message_parse_query (struct rspamd_http_message *msg)
                                                g_assert (key != NULL);
                                                if (p > c) {
                                                        value = rspamd_fstring_new_init (c, p - c);
-                                                       value_tok = g_slice_alloc (sizeof (*value_tok));
-                                                       value_tok->begin = value->str;
+                                                       value_tok = rspamd_ftok_map (value);
                                                        value_tok->len = rspamd_decode_url (value->str,
                                                                        value->str,
                                                                        value->len);
                                                }
                                                else {
                                                        value = rspamd_fstring_new_init ("", 0);
-                                                       value_tok = g_slice_alloc (sizeof (*value_tok));
-                                                       value_tok->begin = value->str;
-                                                       value_tok->len = value->len;
+                                                       value_tok = rspamd_ftok_map (value);
                                                }
 
-                                               g_hash_table_insert (res, key_tok, value_tok);
+                                               g_hash_table_replace (res, key_tok, value_tok);
                                                key = value = NULL;
+                                               key_tok = value_tok = NULL;
                                                state = parse_ampersand;
                                        }
                                        else {