diff options
| author | apnadkarni <apnmbx-wits@yahoo.com> | 2023-09-05 06:10:23 (GMT) |
|---|---|---|
| committer | apnadkarni <apnmbx-wits@yahoo.com> | 2023-09-05 06:10:23 (GMT) |
| commit | 381c827ae8477c27cb4291cb0fa9c5f84581730c (patch) | |
| tree | 35411e4a59dd4e1245b92c6413f5ae03acdd6399 /generic/tclTest.c | |
| parent | 11de34bf3a27c72a010eb7e510241a27027c4c54 (diff) | |
| parent | 22f59c102a2c3880b0e8aa0b3cae623411e84b2f (diff) | |
| download | tcl-381c827ae8477c27cb4291cb0fa9c5f84581730c.zip tcl-381c827ae8477c27cb4291cb0fa9c5f84581730c.tar.gz tcl-381c827ae8477c27cb4291cb0fa9c5f84581730c.tar.bz2 | |
Fix [b5ac3e3786] - Tcl_GetUniChar oob read
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 */ |
