From: Vsevolod Stakhov Date: Mon, 13 Jan 2020 13:16:13 +0000 (+0000) Subject: [Fix] Fix dealing with `\0` in ucl strings and JSON X-Git-Tag: 2.3~118 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f3a1fc705ed0fa856c1ce8eab307ec8607f15096;p=thirdparty%2Frspamd.git [Fix] Fix dealing with `\0` in ucl strings and JSON --- diff --git a/contrib/libucl/ucl_chartable.h b/contrib/libucl/ucl_chartable.h index db9f02900c..043b626899 100644 --- a/contrib/libucl/ucl_chartable.h +++ b/contrib/libucl/ucl_chartable.h @@ -27,7 +27,7 @@ #include "ucl_internal.h" static const unsigned int ucl_chartable[256] = { -UCL_CHARACTER_VALUE_END, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, +UCL_CHARACTER_JSON_UNSAFE|UCL_CHARACTER_VALUE_END|UCL_CHARACTER_UCL_UNSAFE, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_JSON_UNSAFE|UCL_CHARACTER_UCL_UNSAFE, diff --git a/contrib/libucl/ucl_emitter.c b/contrib/libucl/ucl_emitter.c index d37cdda406..687e6cdae0 100644 --- a/contrib/libucl/ucl_emitter.c +++ b/contrib/libucl/ucl_emitter.c @@ -756,6 +756,9 @@ ucl_elt_string_write_json (const char *str, size_t size, func->ucl_emitter_append_len (c, len, func->ud); } switch (*p) { + case '\0': + func->ucl_emitter_append_len ("\\u0000", 6, func->ud); + break; case '\n': func->ucl_emitter_append_len ("\\n", 2, func->ud); break; diff --git a/contrib/libucl/ucl_util.c b/contrib/libucl/ucl_util.c index 5ef83e31b1..830aaa14c9 100644 --- a/contrib/libucl/ucl_util.c +++ b/contrib/libucl/ucl_util.c @@ -2244,6 +2244,7 @@ ucl_object_fromstring_common (const char *str, size_t len, enum ucl_string_flags if (ucl_test_character (*p, UCL_CHARACTER_JSON_UNSAFE | UCL_CHARACTER_WHITESPACE_UNSAFE)) { switch (*p) { case '\v': + case '\0': escaped_len += 5; break; case ' ': @@ -2279,6 +2280,14 @@ ucl_object_fromstring_common (const char *str, size_t len, enum ucl_string_flags *d++ = '\\'; *d = 'f'; break; + case '\0': + *d++ = '\\'; + *d++ = 'u'; + *d++ = '0'; + *d++ = '0'; + *d++ = '0'; + *d = '0'; + break; case '\v': *d++ = '\\'; *d++ = 'u';