Overview
| Artifact ID: | 3e0f6aaaad97c97edfe94e082a8bfe208079594650932a315bdb76c3125cbfcb |
|---|---|
| Ticket: | c9f0520f7e783fa926bf935295d204895f890499
ckalloc argument overflow in Tcl_SplitList with a string about 1 |
| User & Date: | elio_du on 2025-07-09 15:45:39 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-plain"
- comment changed to:
The ckalloc tries to allocate size * sizeof(char*) + length + 1, if since sizeof(char*) in 64bit machine is 8 bytes, for the extreme case string is "0 1 2 3 4 5 ...", size can be so size is half size of string itself, so it takes much smaller string to cause size * sizeof(char*) + length + 1 to hit the 2^32 limit. This issue is not presenting in Tcl 9 as datatype is now 64bit, still would rather Tcl_panic with some error message instead of SEGV directly. To reproduce: --------------------------------------------- static int Crash_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if (objc < 2) { return TCL_ERROR; } const char * str = Tcl_GetString(objv[1]); char **list_elements = NULL; #if TCL_MAJOR_VERSION == 9 long int list_sz = 0; (void)Tcl_SplitList(interp, str, &list_sz, (CONST86 char ***)&list_elements); #else int list_sz = 0; (void)Tcl_SplitList(interp, str, &list_sz, (CONST84 char ***)&list_elements); #endif printf("SPLITTED INTO %d elements\n", list_sz); for (long int i = 0; i < list_sz; i ++) { if (i % 1024 == 0) { printf("%ld:%s\n", i, list_elements[i]); } } Tcl_SetObjResult(interp, Tcl_NewStringObj("Crash", -1)); return TCL_OK; } /* * Crash_Init -- Called when Tcl loads your extension. */ int DLLEXPORT Crash_Init(Tcl_Interp *interp) { if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { return TCL_ERROR; } /* changed this to check for an error - GPS */ if (Tcl_PkgProvide(interp, "Crash", "1.0") == TCL_ERROR) { return TCL_ERROR; } Tcl_CreateObjCommand(interp, "crash", Crash_Cmd, NULL, NULL); return TCL_OK; } ----------------------------------------- Test.tcl: ---------------------------------------- load ./libcrash.so # create a huge string # crash by 26 in 8.6.11 set limit 26 set str "0 1 2 3 4 5 6 7 8 9 " for { set i 0 } { $i < $limit } { incr i } { set str "$str $str" puts "doubled $i: [expr [string length $str] / 1024.0 / 1024] MB" } crash "$str" exit ------------------------------------------- - foundin changed to: "8.6.11"
- is_private changed to: "0"
- login: "elio_du"
- priority changed to: "5 Medium"
- private_contact changed to: "36ae4f4121e0beea41dc8655c6d0658cff1db08d"
- resolution changed to: "None"
- severity changed to: "Critical"
- status changed to: "Open"
- submitter changed to: "elio_du"
- subsystem changed to: "11. Conversions from String"
- title changed to:
ckalloc argument overflow in Tcl_SplitList with a string about 1
- type changed to: "Bug"