diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-12-03 12:27:42 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-12-03 12:27:42 (GMT) |
| commit | 9e0083e9f07d37493c802ab11661736fa680e12c (patch) | |
| tree | 739b0a8816861affd8d358ef6699c610425b0b57 /generic/tclParse.c | |
| parent | 36f4518f890ff81b22fbf1575775ffaf1c1a149b (diff) | |
| download | tcl-9e0083e9f07d37493c802ab11661736fa680e12c.zip tcl-9e0083e9f07d37493c802ab11661736fa680e12c.tar.gz tcl-9e0083e9f07d37493c802ab11661736fa680e12c.tar.bz2 | |
Fix [3cd9bea1e6]: check-in [43032d7ba3] potential problems. Also don't allow surrogates in \U?????? syntax.
Diffstat (limited to 'generic/tclParse.c')
| -rw-r--r-- | generic/tclParse.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/generic/tclParse.c b/generic/tclParse.c index 4f30f8b..b42ff5c 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -870,7 +870,7 @@ TclParseBackslash( count = 2; switch (*p) { /* - * Note: in the conversions below, use absolute values (e.g., 0xa) + * Note: in the conversions below, use absolute values (e.g., 0xA) * rather than symbolic values (e.g. \n) that get converted by the * compiler. It's possible that compilers on some platforms will do * the symbolic conversions differently, which could result in @@ -884,19 +884,19 @@ TclParseBackslash( result = 0x8; break; case 'f': - result = 0xc; + result = 0xC; break; case 'n': - result = 0xa; + result = 0xA; break; case 'r': - result = 0xd; + result = 0xD; break; case 't': result = 0x9; break; case 'v': - result = 0xb; + result = 0xB; break; case 'x': count += TclParseHex(p+1, (numBytes > 3) ? 2 : numBytes-2, &result); @@ -921,11 +921,13 @@ TclParseBackslash( */ result = 'u'; #if TCL_UTF_MAX > 3 - } else if (((result & 0xDC00) == 0xD800) && (count == 6) && (p[5] == '\\') && (p[6] == 'u') && (numBytes >= 10)) { - /* If high surrogate is immediately followed by a low surrogate escape, combine them. */ + } else if (((result & 0xDC00) == 0xD800) && (count == 6) + && (p[5] == '\\') && (p[6] == 'u') && (numBytes >= 10)) { + /* If high surrogate is immediately followed by a low surrogate + * escape, combine them into one character. */ int low; int count2 = TclParseHex(p+7, 4, &low); - if ((low & 0xDC00) == 0xDC00) { + if ((count2 == 4) && ((low & 0xDC00) == 0xDC00)) { result = ((result & 0x3FF)<<10 | (low & 0x3FF)) + 0x10000; count += count2 + 2; } @@ -939,6 +941,9 @@ TclParseBackslash( * No hexadigits -> This is just "U". */ result = 'U'; + } else if ((result | 0x7FF) == 0xDFFF) { + /* Upper or lower surrogate, not allowed in this syntax. */ + result = 0xFFFD; } break; case '\n': |
