Artifacts Associated With Ticket 6015221f59
Ticket change [90eaad9614] (rid 153462) by anonymous on 2017-05-03 02:55:38:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
if "binary scan" is requesting too much character data, it just segfaults instead of complaining that too much data is requested. % binary scan x a172983798173981a r n Segmentation fault (core dumped)
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "ab5c04693d4ea3b3339a1e41947ceb8da8054625"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "16. Commands A-H"
- title initialized to: "binary scan segfaults when too much a is requested"
- type initialized to: "Bug"
Ticket change [ac56560238] (rid 153463) by aspect on 2017-05-03 06:21:31:
- icomment:
playing around in gdb on core-8-5-branch, the problem in this case seems to be that after GetFormatSpec(&format, &cmd, &count, &flags), count is added to offset making it point outside the buffer. Specifically, this is wrong: GetFormatSpec( .. int *countPtr .. ) { (*countPtr) = strtoul( .. ) } Similar issue likely exists in [binary format]. Simplest fix is probably to return 0 if the strtoul() result is <0. Else Tcl_BinaryObjCmd() needs to check after each call whether count is BINARY_UNSIGNED, BINARY_ALL, >=0 and otherwise TCL_ERROR. Note: this looks like a relatively easily exploitable memory corruption bug, for anywhere untrusted users can provide format arguments to [binary]. - login: "aspect"
- mimetype: "text/plain"
- icomment:
Ticket change [136ef3e43e] (rid 153464) by jan.nijtmans on 2017-05-03 07:50:58:
- icomment:
Actually, Segmentation faults from pure Tcl code is always bad .... It would be nice if this could be fixed in at least Tcl 8.6.7. Suggestion for a fix always welcome?
- login: "jan.nijtmans"
- mimetype: "text/plain"
- severity changed to: "Severe"
- icomment:
Ticket change [0a294c5250] (rid 153466) by sebres on 2017-05-03 09:29:25:
- assignee changed to: "sebres"
- foundin changed to: ">= 8.5 (*nix only)"
- icomment:
I guess something like this in GetFormatSpec would be more appreciated: ``` if (*countPtr) < 0 { countPtr = BINARY_ALL; } ``` According to documentation "count is a non-negative decimal integer", so I think in this case BINARY_ALL is a little bit better as boom. If no objections I would fix it this way in all 3 major branches (including test cases). BTW. Strange is, that at all not reproduceable under windows (neither x86 nor x64), but pretty segfaulting on linux in all versions. - login: "sebres"
- mimetype: "text/plain"
- priority changed to: "7 High"
- severity changed to: "Critical"
Ticket change [8132ecf041] (rid 153468) by sebres on 2017-05-03 09:49:27:
- icomment:
Another way would be to redefine GetFormatSpec (and count as unsigned), like: GetFormatSpec( .. unsigned int *countPtr .. ) unsigned int count; and #define BINARY_ALL ((unsigned int)-1) ... So "overflow" will reach both special cases only by following ranges (accoring INT_MAX): binary scan x a[format %ld 0xffffffff]a r n; # equal BINARY_ALL binary scan x a[format %ld 0xfffffffe]a r n; # equal BINARY_UNSIGNED
- login: "sebres"
- mimetype: "text/plain"
- icomment:
Ticket change [8a305859d0] (rid 153572) by dgp on 2017-05-04 16:00:31:
- icomment:
Seems to me the root of the issue is making a call to strtoul() without checking for the various errors that can result from it. This has been wrong since the dawn of Tcl's CVS history. There are a handful of other strtoul() calls here and there in Tcl. An audit of all of them would be a good idea.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [dfb562cf4d] (rid 153590) by dgp on 2017-05-05 19:18:30:
- assignee changed to: "dgp"
- closedate changed to: "2457879.30452203"
- closer changed to: "dgp"
- icomment:
fixed on all dev branches
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- subsystem changed to: "12. ByteArray Object"