Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 35023c61a153b6f87878fdc653bc4c8a29674b81
Ticket: 3484402fffffffffffffffffffffffffffffffff
off-by-one address error in AppendUnicodeToUnicodeRep
User & Date: sebres on 2012-02-07 00:02:40
Changes

  1. icomment:
    That could be calculated mathematically :
    
    stringPtr->uallocated; - amount of space actually allocated for the 
      Unicode string (minus 2 bytes for the termination char).
    stringPtr->unicode - is a "unsigned short []" - also "unsigned short *" 
      - also mathematically, stringPtr->unicode + 1 == ADDR + 2
    
    ------------------------------------------------------------------------------------
    
    For example by string "abc":
    
       stringPtr->unicode = 0xADDR0000
       stringPtr->uallocated = 6 // + 2 bytes for NTS zeros;
       0xADDR0000:    61 00    62 00    63 00  [ 00 00 ]
       stringPtr->unicode + 1 + stringPtr->uallocated / sizeof(Tcl_UniChar) = 
       stringPtr->unicode + 1 + 6/2 = stringPtr->unicode + 4 (offset) = ADDR + 8 (mathematically)
    
    When: 
       unicode = 0xADDR0004 // within buffer, "unicode" points to the last UNICHAR before NTS
       0xADDR0000:   61 00    62 00 -> 63 00  [ 00 00 ]
                                                             
    unicode <= stringPtr->unicode + 1 + stringPtr->uallocated / sizeof(Tcl_UniChar)
       4 <= 8 == true
    
    --------------------------------
    
    When: 
       unicode = 0xADDR0006 // within buffer, "unicode" points to NTS after the last UNICHAR
       0xADDR0000:   61 00    62 00    63 00 ->[ 00 00 ]
    
    unicode <= stringPtr->unicode + 1 + stringPtr->uallocated / sizeof(Tcl_UniChar)
       6 <= 8 = true
    
    --------------------------------
    
    When: 
       unicode = 0xADDR0008 // out of buffer, "unicode" points to ANOTHER unicode string.
       0xADDR0000:   61 00    62 00    63 00   [ 00 00 ] -> .. .. ..
    
    unicode <= stringPtr->unicode + 1 + stringPtr->uallocated / sizeof(Tcl_UniChar)
    8 <= 8 = true
    
    That is why it must be the following ("<=" should be replaced with "<", but "+1" must remain) :
    [SOLUTION BEGIN]
    if (unicode >= stringPtr->unicode && unicode < stringPtr->unicode
    + 1 + stringPtr->uallocated / sizeof(Tcl_UniChar)) {
    offset = unicode - stringPtr->unicode;
    }
    [SOLUTION END]
    
    
  2. login: "sebres"
  3. mimetype: "text/plain"
  4. username: "sebres"