commit f3a1fc7: [Fix] Fix dealing with `\0` in ucl strings and JSON

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jan 13 14:00:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-01-13 13:16:13 +0000
URL: https://github.com/rspamd/rspamd/commit/f3a1fc705ed0fa856c1ce8eab307ec8607f15096

[Fix] Fix dealing with `\0` in ucl strings and JSON

---
 contrib/libucl/ucl_chartable.h | 2 +-
 contrib/libucl/ucl_emitter.c   | 3 +++
 contrib/libucl/ucl_util.c      | 9 +++++++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/contrib/libucl/ucl_chartable.h b/contrib/libucl/ucl_chartable.h
index db9f02900..043b62689 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 d37cdda40..687e6cdae 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 5ef83e31b..830aaa14c 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';


More information about the Commits mailing list