summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2017-08-11 18:13:57 +0300
committerValentin Bartenev <vbart@nginx.com>2017-08-11 18:13:57 +0300
commit8bb88aaf5186721db20dd07e1976d52a1bc8332a (patch)
tree1fec35932eaed1cd6ce7117ecb8289b3a19438a2
parent39a6a4c973dd378f1fad9d2514d7857fe491df4b (diff)
downloadunit-8bb88aaf5186721db20dd07e1976d52a1bc8332a.tar.gz
unit-8bb88aaf5186721db20dd07e1976d52a1bc8332a.tar.bz2
Fixed parsing of JSON encoded UTF-16 surrogate pairs.
Diffstat (limited to '')
-rw-r--r--src/nxt_conf.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/nxt_conf.c b/src/nxt_conf.c
index bad9165b..4164bd5b 100644
--- a/src/nxt_conf.c
+++ b/src/nxt_conf.c
@@ -1375,31 +1375,28 @@ nxt_conf_json_parse_string(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
p += 4;
- if (utf < 0xd800 || utf > 0xdbff || utf_high) {
- break;
- }
+ if (utf_high != 0) {
+ if (nxt_slow_path(utf < 0xdc00 || utf > 0xdfff)) {
+ return NULL;
+ }
- utf_high = utf;
- utf = 0;
+ utf = ((utf_high - 0xd800) << 10) + (utf - 0xdc00) + 0x10000;
- if (p[0] != '\\' || p[1] != 'u') {
break;
}
- p += 2;
- }
+ if (utf < 0xd800 || utf > 0xdfff) {
+ break;
+ }
- if (utf_high != 0) {
- if (nxt_slow_path(utf_high < 0xd800
- || utf_high > 0xdbff
- || utf < 0xdc00
- || utf > 0xdfff))
- {
- /* Invalid surrogate pair. */
+ if (utf > 0xdbff || p[0] != '\\' || p[1] != 'u') {
return NULL;
}
- utf = ((utf_high - 0xd800) << 10) + (utf - 0xdc00);
+ p += 2;
+
+ utf_high = utf;
+ utf = 0;
}
s = nxt_utf8_encode(s, utf);