Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-08-28
02:35 • Closed ticket [2845535fff]: string overflow panic in format plus 7 other c... artifact: 9fc0ac7aed user: dgp
02:35 • Ticket [2845535fff]: 4 changes artifact: 07aaffd86f user: dgp
02:22 • Ticket [2845535fff]: 4 changes artifact: 3088fedff2 user: dgp
02:21 • Add attachment 2845535.patch to ticket [2845535fff] artifact: 04c6492719 user: dgp
02:21 • Ticket [2845535fff] string overflow panic in format status still Open with... artifact: 5d4946999b user: dgp
01:34 • Ticket [2845535fff]: 4 changes artifact: fbbc128828 user: dgp
2009-08-27
23:30 • Ticket [2845535fff]: 4 changes artifact: f6b1070a59 user: dgp
23:23 • Ticket [2845535fff]: 1 change artifact: 9c4ad130b3 user: dgp
23:23 • Ticket [2845535fff]: 4 changes artifact: ac0cdaece9 user: dgp
21:05 • Ticket [2845535fff]: 1 change artifact: efbd17b214 user: dgp
21:05 • Ticket [2845535fff]: 4 changes artifact: 81795d0871 user: dgp
19:58 • Ticket [2845535fff]: 4 changes artifact: 325e5d69b0 user: mistachkin
19:45 • Ticket [2845535fff]: 2 changes artifact: 0a0700d4e7 user: dkf
12:38 • New ticket [2845535fff]. artifact: dfb26b4704 user: mistachkin

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: