]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Strictly filter bad characters when emittin json
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 8 Feb 2017 13:32:30 +0000 (13:32 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 8 Feb 2017 13:46:57 +0000 (13:46 +0000)
contrib/libucl/ucl_emitter_utils.c
contrib/libucl/ucl_internal.h

index 95ac9a5d57764f053c67a48bab7c142e6ab69351..3559eb63df929d02e9c4bd2abea6da0b2221cf63 100644 (file)
@@ -102,7 +102,7 @@ ucl_elt_string_write_json (const char *str, size_t size,
        func->ucl_emitter_append_character ('"', 1, func->ud);
 
        while (size) {
-               if (ucl_test_character (*p, UCL_CHARACTER_JSON_UNSAFE)) {
+               if (ucl_test_character (*p, UCL_CHARACTER_JSON_UNSAFE|UCL_CHARACTER_DENIED)) {
                        if (len > 0) {
                                func->ucl_emitter_append_len (c, len, func->ud);
                        }
@@ -128,6 +128,10 @@ ucl_elt_string_write_json (const char *str, size_t size,
                        case '"':
                                func->ucl_emitter_append_len ("\\\"", 2, func->ud);
                                break;
+                       default:
+                               /* Emit unicode unknown character */
+                               func->ucl_emitter_append_len ("\\uFFFD", 5, func->ud);
+                               break;
                        }
                        len = 0;
                        c = ++p;
@@ -138,9 +142,11 @@ ucl_elt_string_write_json (const char *str, size_t size,
                }
                size --;
        }
+
        if (len > 0) {
                func->ucl_emitter_append_len (c, len, func->ud);
        }
+
        func->ucl_emitter_append_character ('"', 1, func->ud);
 }
 
index 444a40e3820320205b696d61f4ea38d59ddeb35f..44a8fe70e3a93918b927d21fe36f09c120e4fac0 100644 (file)
@@ -128,19 +128,19 @@ enum ucl_parser_state {
 };
 
 enum ucl_character_type {
-       UCL_CHARACTER_DENIED = 0,
-       UCL_CHARACTER_KEY = 1,
-       UCL_CHARACTER_KEY_START = 1 << 1,
-       UCL_CHARACTER_WHITESPACE = 1 << 2,
-       UCL_CHARACTER_WHITESPACE_UNSAFE = 1 << 3,
-       UCL_CHARACTER_VALUE_END = 1 << 4,
-       UCL_CHARACTER_VALUE_STR = 1 << 5,
-       UCL_CHARACTER_VALUE_DIGIT = 1 << 6,
-       UCL_CHARACTER_VALUE_DIGIT_START = 1 << 7,
-       UCL_CHARACTER_ESCAPE = 1 << 8,
-       UCL_CHARACTER_KEY_SEP = 1 << 9,
-       UCL_CHARACTER_JSON_UNSAFE = 1 << 10,
-       UCL_CHARACTER_UCL_UNSAFE = 1 << 11
+       UCL_CHARACTER_DENIED = (1 << 0),
+       UCL_CHARACTER_KEY = (1 << 1),
+       UCL_CHARACTER_KEY_START = (1 << 2),
+       UCL_CHARACTER_WHITESPACE = (1 << 3),
+       UCL_CHARACTER_WHITESPACE_UNSAFE = (1 << 4),
+       UCL_CHARACTER_VALUE_END = (1 << 5),
+       UCL_CHARACTER_VALUE_STR = (1 << 6),
+       UCL_CHARACTER_VALUE_DIGIT = (1 << 7),
+       UCL_CHARACTER_VALUE_DIGIT_START = (1 << 8),
+       UCL_CHARACTER_ESCAPE = (1 << 9),
+       UCL_CHARACTER_KEY_SEP = (1 << 10),
+       UCL_CHARACTER_JSON_UNSAFE = (1 << 11),
+       UCL_CHARACTER_UCL_UNSAFE = (1 << 12)
 };
 
 struct ucl_macro {