Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[string repeat] may crash

Closed / Fixed714106ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2003-04-02 18:58:39
The following code crashes a 32-bit machine (PC):

set M  [string repeat x  1048576]
set G4 [string repeat $M    4096]

The culprit is the unchecked length multiplication
in line 2110 in "generic/tclCmdMZ.c:

length2             = length1 * count;

That can overflow.  As a result, much less memory
gets allocated, than filled after allocation.

I suggest to check the multiplication by back-division:

if ((length2 / count) != length1) { ...error... }

Heiner [email protected]
hobbsplain2003-05-11 06:57:38
Logged In: YES 
user_id=72656

Closed with the attached patch.  I didn't add a test because it 
would have different behavior on 64-bit ILP systems.  Fixed for 
8.4.3 and 8.5.
hobbsplain2003-05-11 06:57:39
File Added - 50083: 714106.strrepeat
Log in (anonymous is fine) to add a comment.

Attachments: