Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 8f27ef47d6eb2fd7945f79d94ab056b17523a394
Ticket: 2494093fffffffffffffffffffffffffffffffff
buffer overflow in AppendUnicodeToUnicode() -> SEGFAULT
User & Date: matzek on 2009-02-02 17:45:04
Changes

  1. icomment:
    peppered the code with printf()s again ... on Solaris revealed:
    
    >>> numChars 1073733632; ualloc(numChars) 2147467264 >= uallocated 2147460096?
    >>>  attempt to reallocate 4294934528
    >>>   reallocate 2147476480
    >>>  new buffer @ 0x2109a0, old was @ 0x2109a0
    >>> copy 8192 from 0x206970 to 0x8020a9b0
    
    >>> numChars 1073737728; ualloc(numChars) 2147475456 >= uallocated 2147476480?
    >>> copy 8192 from 0x206970 to 0x8020c9b0
    
    >>> numChars 1073741824; ualloc(numChars) 2147483648 >= uallocated 2147476480?
    >>>  attempt to reallocate 0
    >>>  new buffer @ 0x1f6b28, old was @ 0x2109a0
    >>> copy 8192 from 0x206970 to 0x801f4b38
    
    >>> numChars 1073745920; ualloc(numChars) 2147491840 >= uallocated 0?
    >>>  attempt to reallocate 16384
    >>>  new buffer @ 0x20a980, old was @ 0x1f6b28
    >>> copy 8192 from 0x206970 to 0x8020a990
    
    >>> numChars 1073750016; ualloc(numChars) 2147500032 >= uallocated 16384?
    >>>  attempt to reallocate 32768
    >>>  new buffer @ 0x20a980, old was @ 0x20a980
    >>> copy 8192 from 0x206970 to 0x8020c990
    
    >>> numChars 1073754112; ualloc(numChars) 2147508224 >= uallocated 32768?
    >>>  attempt to reallocate 49152
    >>>  new buffer @ 0x20a980, old was @ 0x20a980
    >>> copy 8192 from 0x206970 to 0x8020e990
    
    >>> numChars 1073758208; ualloc(numChars) 2147516416 >= uallocated 49152?
    >>>  attempt to reallocate 65536
    >>>  new buffer @ 0x20a980, old was @ 0x20a980
    >>> copy 8192 from 0x206970 to 0x80210990
    
    So there is an entry that show that we attempt to reallocate 0 bytes. The preprocessor result is ...
    
        numChars = stringPtr->numChars + appendNumChars;
    
        if ( ( ( numChars ) * sizeof ( Tcl_UniChar ) ) >= stringPtr->uallocated) {
         stringPtr->uallocated =  ( ( 2 * numChars ) * sizeof ( Tcl_UniChar ) );
    tmpString =  ( String * ) ( ( ( stringPtr -> uallocated ) > 2147483647 - ( sizeof ( String ) - sizeof ( Tcl_UniChar ) + ( 0 ) ) ) ? 0 : Tcl_AttemptRealloc ( ( char * ) stringPtr , ( unsigned ) ( sizeof ( String ) - sizeof ( Tcl_UniChar ) + ( ( stringPtr -> uallocated ) ? ( stringPtr -> uallocated ) : sizeof ( Tcl_UniChar ) ) ) ) );
    if (tmpString ==  0 ) {
        stringPtr->uallocated =
             ( ( numChars + appendNumChars ) * sizeof ( Tcl_UniChar ) ) 
    +  1024 ;
        tmpString =  ( String * ) ( ( ( stringPtr -> uallocated ) > 2147483647 - ( sizeof ( String ) - sizeof ( Tcl_UniChar ) + ( 0 ) ) ) ? ( Tcl_Panic ( "unable to alloc %u bytes" , ( sizeof ( String ) - sizeof ( Tcl_UniChar ) + ( stringPtr -> uallocated ) ) ) , ( char * ) 0 ) : Tcl_Realloc ( ( char * ) stringPtr , ( unsigned ) ( sizeof ( String ) - sizeof ( Tcl_UniChar ) + ( ( stringPtr -> uallocated ) ? ( stringPtr -> uallocated ) : sizeof ( Tcl_UniChar ) ) ) ) );
    }
    stringPtr = tmpString;
     ( objPtr ) -> internalRep . otherValuePtr = ( void * ) ( stringPtr );
        }
    
    So we attempt to realloc 0 bytes, that does not fail (and is legal, should free the memory) and even seem to return some pointer...
    
    -- Matthias Kraft
    
    
  2. login: "matzek"
  3. mimetype: "text/plain"
  4. username: "matzek"