string overflow panic in [format]
Closed / Fixed2845535fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-08-27 12:38:31
The following command triggers a crash in 8.4, 8.5, and HEAD:
format "%.2147483647f" 2
The following command triggers a crash in 8.5 and HEAD (in 8.4 it produces some kind of result):
format "%2147483647.f" 2
The following code (near line 2187) in "generic\tclStringObj.c" is a bit problematic due to unchecked usage of sprintf with a fixed size buffer:
char spec[2*TCL_INTEGER_SPACE + 9], *p = spec;
<snip>
if (width) {
p += sprintf(p, "%d", width);
if (width > length) {
length = width;
}
}
if (gotPrecision) {
*p++ = '.';
p += sprintf(p, "%d", precision);
length += precision;
}
dkf Ticket [2845535fff]: 2 changes
[History diff]2009-08-27 19:45:47
mistachkinplain2009-08-27 19:58:58
Further analysis reveals that I am tired. The actual line (near 2235) which causes the problem is: Tcl_SetObjLength(segment, sprintf(bytes, spec, d));
dgpplain2009-08-27 21:05:40
Any relation to 2838354 ?
dgp Ticket [2845535fff]: 1 change
[History diff]2009-08-27 21:05:41
dgpplain2009-08-27 23:23:04
on the 8.5 and HEAD branches I see a panic, not a crash: % format %.2147483647f 2 Tcl_SetObjLength: negative length requested: -2147483329 (integer overflow?) In 8.4, I see: % format %.2147483647f 2 %
dgp Ticket [2845535fff]: 1 change
[History diff]2009-08-27 23:23:05
dgpplain2009-08-27 23:30:50
For the second example, on a system where I avoid a mem alloc panic, I also see a panic, not a crash: % format "%2147483647.f" 2 Tcl_SetObjLength: negative length requested: -1 (integer overflow?)
dgpplain2009-08-28 01:34:29
The Tcl code is not written with the possibility that sprintf() might raise an error, which according to the linux platform docs is done by returning a negative value.
dgpplain2009-08-28 02:21:58
File Added - 340830: 2845535.patch
dgpplain2009-08-28 02:22:14
patch attached
dgpplain2009-08-28 02:35:09
patch committed to fix in 8.5.8+ consider either Works For Me or Wont Fix for 8.4.
dgpplain2009-08-28 02:35:14
allow_comments - 1
Log in (anonymous is fine) to add a comment.
Attachments:
- 2845535.patch [download] added by dgp on 2009-08-28 02:21:58. [details]