diff options
| author | apnadkarni <apnmbx-wits@yahoo.com> | 2023-09-05 05:44:41 (GMT) |
|---|---|---|
| committer | apnadkarni <apnmbx-wits@yahoo.com> | 2023-09-05 05:44:41 (GMT) |
| commit | 38d04b648dd088e9c28b707603b82dcac81411e5 (patch) | |
| tree | 8f0468cdb02ccb4ad8d09063d19e8bb6adc0fb5b /generic/tclTest.c | |
| parent | 11de34bf3a27c72a010eb7e510241a27027c4c54 (diff) | |
| download | tcl-38d04b648dd088e9c28b707603b82dcac81411e5.zip tcl-38d04b648dd088e9c28b707603b82dcac81411e5.tar.gz tcl-38d04b648dd088e9c28b707603b82dcac81411e5.tar.bz2 | |
Tcl_GetUniChar out of bounds read - tests
Diffstat (limited to 'generic/tclTest.c')
| -rw-r--r-- | generic/tclTest.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c index f227ec3..47c4b81 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -318,6 +318,7 @@ static Tcl_FSMatchInDirectoryProc SimpleMatchInDirectory; static Tcl_ObjCmdProc TestUtfNextCmd; static Tcl_ObjCmdProc TestUtfPrevCmd; static Tcl_ObjCmdProc TestNumUtfCharsCmd; +static Tcl_ObjCmdProc TestGetUniCharCmd; static Tcl_ObjCmdProc TestFindFirstCmd; static Tcl_ObjCmdProc TestFindLastCmd; static Tcl_ObjCmdProc TestHashSystemHashCmd; @@ -582,6 +583,8 @@ Tcltest_Init( TestUtfPrevCmd, NULL, NULL); Tcl_CreateObjCommand(interp, "testnumutfchars", TestNumUtfCharsCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "testgetunichar", + TestGetUniCharCmd, NULL, NULL); Tcl_CreateObjCommand(interp, "testfindfirst", TestFindFirstCmd, NULL, NULL); Tcl_CreateObjCommand(interp, "testfindlast", @@ -7146,6 +7149,34 @@ TestNumUtfCharsCmd( return TCL_OK; } + +/* + * Used to check correct operation of Tcl_GetUniChar + * testgetunichar STRING INDEX + * This differs from just using "string index" in being a direct + * call to Tcl_GetUniChar without any prior range checking. + */ +static int +TestGetUniCharCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter */ + int objc, /* Number of arguments */ + Tcl_Obj *const objv[] /* Argument strings */ + ) +{ + int index; + int c ; + if (objc != 3) { + Tcl_WrongNumArgs(interp, 1, objv, "STRING INDEX"); + return TCL_ERROR; + } + Tcl_GetIntFromObj(interp, objv[2], &index); + c = Tcl_GetUniChar(objv[1], index); + Tcl_SetObjResult(interp, Tcl_NewIntObj(c)); + + return TCL_OK; +} + /* * Used to check correct operation of Tcl_UtfFindFirst */ |
