]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Another try to fix add headers compatibility logic
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 23 Aug 2022 22:53:26 +0000 (23:53 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 23 Aug 2022 22:53:26 +0000 (23:53 +0100)
Issue: #4246

src/libserver/milter.c

index a84506720c41b502ea36a40fa8443cf6804eabca..e559495fb03c1ec1fb18307d8bc9ae44e9f3970e 100644 (file)
@@ -1747,7 +1747,7 @@ static gboolean
 rspamd_milter_process_milter_block (struct rspamd_milter_session *session,
                const ucl_object_t *obj, struct rspamd_action *action)
 {
-       const ucl_object_t *elt, *cur, *cur_elt;
+       const ucl_object_t *elt, *cur;
        ucl_object_iter_t it;
        struct rspamd_milter_private *priv = session->priv;
        GString *hname, *hvalue;
@@ -1781,32 +1781,47 @@ rspamd_milter_process_milter_block (struct rspamd_milter_session *session,
                        it = NULL;
 
                        while ((cur = ucl_object_iterate (elt, &it, true)) != NULL) {
-                               ucl_object_iter_t *elt_it;
 
-                               elt_it = ucl_object_iterate_new (cur);
                                const char *key_name = ucl_object_key (cur);
 
-                               while ((cur_elt = ucl_object_iterate_safe (elt_it, false)) != NULL) {
-                                       if (ucl_object_type (cur_elt) == UCL_STRING) {
-                                               hname = g_string_new (key_name);
-                                               hvalue = g_string_new (ucl_object_tostring (cur_elt));
-
-                                               rspamd_milter_send_action (session,
-                                                               RSPAMD_MILTER_ADDHEADER,
-                                                               hname, hvalue);
-                                               g_string_free (hname, TRUE);
-                                               g_string_free (hvalue, TRUE);
+                               if (ucl_object_type (cur) == UCL_STRING) {
+                                       /*
+                                        * Legacy support of {"name": "value", ... } with
+                                        * multiple names under the same name
+                                        */
+                                       ucl_object_iter_t *elt_it;
+                                       const ucl_object_t *cur_elt;
+
+                                       elt_it = ucl_object_iterate_new (cur);
+                                       while ((cur_elt = ucl_object_iterate_safe (elt_it, false)) != NULL) {
+                                               if (ucl_object_type (cur_elt) == UCL_STRING) {
+                                                       hname = g_string_new (key_name);
+                                                       hvalue = g_string_new (ucl_object_tostring (cur_elt));
+
+                                                       rspamd_milter_send_action (session,
+                                                                       RSPAMD_MILTER_ADDHEADER,
+                                                                       hname, hvalue);
+                                                       g_string_free (hname, TRUE);
+                                                       g_string_free (hvalue, TRUE);
+                                               }
+                                               else {
+                                                       msg_warn_milter("legacy header with name %s, that has not a string value: %s",
+                                                                       key_name, ucl_object_type_to_string(cur_elt->type));
+                                               }
                                        }
-                                       else if (ucl_object_type (cur_elt) == UCL_OBJECT) {
+                                       ucl_object_iterate_free (elt_it);
+                               }
+                               else {
+                                       if (ucl_object_type (cur) == UCL_OBJECT) {
                                                rspamd_milter_extract_single_header (session,
-                                                               key_name, cur_elt);
+                                                               key_name, cur);
                                        }
-                                       else if (ucl_object_type (cur_elt) == UCL_ARRAY) {
+                                       else if (ucl_object_type (cur) == UCL_ARRAY) {
                                                /* Multiple values for the same key */
                                                ucl_object_iter_t *array_it;
                                                const ucl_object_t *array_elt;
 
-                                               array_it = ucl_object_iterate_new (cur_elt);
+                                               array_it = ucl_object_iterate_new (cur);
 
                                                while ((array_elt = ucl_object_iterate_safe (array_it,
                                                                true)) != NULL) {
@@ -1816,9 +1831,11 @@ rspamd_milter_process_milter_block (struct rspamd_milter_session *session,
 
                                                ucl_object_iterate_free (array_it);
                                        }
+                                       else {
+                                               msg_warn_milter("non-legacy header with name %s, that has unsupported value type: %s",
+                                                               key_name, ucl_object_type_to_string(cur->type));
+                                       }
                                }
-
-                               ucl_object_iterate_free (elt_it);
                        }
                }