summaryrefslogtreecommitdiffstats
path: root/generic/tclInt.h
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-01 13:38:22 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-01 13:38:22 (GMT)
commit9eaf82b745ac07bc55f7238813c449fc5a447cf8 (patch)
treef421a15863ac0ae1148013bf95a401b8eeba0357 /generic/tclInt.h
parentba28f4892362a62309d8809b4dc5099a888a9f91 (diff)
parent62c00ac54a6f93ad1324d7e7aa5ef43623ca2415 (diff)
downloadtcl-9eaf82b745ac07bc55f7238813c449fc5a447cf8.zip
tcl-9eaf82b745ac07bc55f7238813c449fc5a447cf8.tar.gz
tcl-9eaf82b745ac07bc55f7238813c449fc5a447cf8.tar.bz2
Fix first part of [ed29806baf]: Tcl_UtfToUniChar reads more than TCL_UTF_MAX bytes.
Tcl_UtfToUniChar() now never reads more than TCL_UTF_MAX bytes any more. The UtfToUtf encoder/decoder is adapted to do attitional checks (more tricky than in Tcl 8.7, since we want compatibility with earlier 8.6 releases). Other callers of Tcl_UtfToUniChar() needs to be revised for the same problem. Most callers will need to change Tcl_UtfToUniChar() -> TclUtfToUCS4() and Tcl_UtfCharComplete() -> TclUCS4Complete(), but that's not done yet.
Diffstat (limited to 'generic/tclInt.h')
-rw-r--r--generic/tclInt.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 5df9aac..593d878 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3184,6 +3184,8 @@ MODULE_SCOPE int TclTrimRight(const char *bytes, int numBytes,
const char *trim, int numTrim);
MODULE_SCOPE int TclUtfCasecmp(const char *cs, const char *ct);
MODULE_SCOPE int TclUtfToUCS4(const char *src, int *ucs4Ptr);
+# define TclUCS4Complete(src, length) (((unsigned)(UCHAR(*(src)) - 0xF0) < 5) \
+ ? ((length) >= 4) : Tcl_UtfCharComplete((src), (length)))
MODULE_SCOPE Tcl_Obj * TclpNativeToNormalized(ClientData clientData);
MODULE_SCOPE Tcl_Obj * TclpFilesystemPathType(Tcl_Obj *pathPtr);
MODULE_SCOPE int TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr,
@@ -4436,8 +4438,8 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
*/
#define TclUtfToUniChar(str, chPtr) \
- ((((unsigned char) *(str)) < 0x80) ? \
- ((*(chPtr) = (unsigned char) *(str)), 1) \
+ (((UCHAR(*(str))) < 0x80) ? \
+ ((*(chPtr) = UCHAR(*(str))), 1) \
: Tcl_UtfToUniChar(str, chPtr))
/*
@@ -4466,11 +4468,11 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
#define TclUtfPrev(src, start) \
(((src) < (start)+2) ? (start) : \
- ((unsigned char) *(src - 1)) < 0x80 ? (src)-1 : \
+ (UCHAR(*((src) - 1))) < 0x80 ? (src)-1 : \
Tcl_UtfPrev(src, start))
#define TclUtfNext(src) \
- ((((unsigned char) *(src)) < 0x80) ? src + 1 : Tcl_UtfNext(src))
+ (((UCHAR(*(src))) < 0x80) ? (src) + 1 : Tcl_UtfNext(src))
/*
*----------------------------------------------------------------