Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 4ca036e992980a4eaa4ca155c3c574e83bf837c6
Ticket: 219417ffffffffffffffffffffffffffffffffff
tcltest errors on io.test module and others
User & Date: andreas_kupries on 2000-11-20 14:15:39
Changes

  1. icomment:
    The log contains several places the compiler warns about. They are
    handled here separately.
    
    There are only four distinct messages, called A-D.
    
    Upfront summary
    ___________________________________________________
    (A) Priority 8, open,   may cause crashes
    (B) Priority 2, closed, no remedy short of rewriting the whole buffer system.
    (C) Priority 2, closed, already fixed (8.4a2)
    (D) Priority 4, closed, look for other reports regarding definition of 'size_t'
    
    ___________________________________________________
    (A)cc: Info: ./../generic/tclEncoding.c, line 1337: In this
    statement, an array sub script expression is either
    less than zero or greater than the largest value that
    can be represented by the size_t type. (badsubscript)
            hex = staticHex - '0';
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The code in question is
    
        char *hex;
        static char staticHex[] = {
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0,
    10, 11, 12, 13, 14, 15
        };
    
    >>  hex = staticHex - '0';
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Comments:
    
    --staticHex declares a mapping from the characters '0'
    upto 'F' (ASCII) into the corresponding 4bit-value
    (nibble).
    
    The flagged statement extends this restricted mapping
    into a mapping from 0x00 upto 0xFF.
    
    The virtual array created thiss way is later (line
    1384ff) accessed via
    
    Tcl_ReadChars(chan, objPtr, 3 + 16 * (16 * 4 + 1), 0);
    p = Tcl_GetString(objPtr);
    [x]hi = (hex[(int)p[0]] << 4) + hex[(int)p[1]];
    [/]dataPtr->toUnicode[hi] = pageMemPtr;
    
    to convert a 2-character hex sequence into the
    corresponding byte value. The following loop does the
    same.
    
    --This code is extremely unsafe with respect to the
    contents of the file containing the encoding. It
    assumes that encoding files always follow the
    rules. Garbage, i.e. non-hex characters will cause the
    interpreter to crash, either in [x] because 'hex' is
    accessed outside of the valid range (= staticHex), or
    in [/] because the computed value of 'hi' is outside
    of the bounds of the array 'toUnicode'. The
    corresponding statements in the loop may cause that
    too.
    
    Because of this unsafety the bug now has priority 8.
    
    
    --I speculate that the code was written this way to
    enhance the performance of the conversion by removing
    the need to subtract '0' from every character used to
    index the array.
    
    Proposed solution:
    
    1)Remove the virtual array and index into 'staticHex'
    directly instead, subtract '0' from each character
    used to do so.
    
    2)Additional checks to ensure that the characters used
    to index into 'staticHex' are in the range '0' ... 'F'
    (or '0' ... '9' and 'A' ... 'F'). Return NULL if these
    checks trigger. This is already the value to be used
    to signal an invalid encodiing file.
    
    ___________________________________________________
    (B)cc: Info: ./../generic/tclIO.c, line 3535: In this statement,
    an array is being accessed outside the bounds specified for
    the array type.  (subscrbounds)
    
                    memcpy((VOID *) (nextPtr->buf + BUFFER_PADDING - extra),
                    --------------------------------^
    
    
    cc: Info: ./../generic/tclIO.c, line 3683: In this statement,
    an array is being accessed outside the bounds specified for
    the array type.  (subscrbounds)
    
    (VOID *) (nextPtr->buf + BUFFER_PADDING - extra),
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In 8.4a2 the code in question has moved to line 3637.
    
        extra = rawLen - gsPtr->rawRead;
    >>  memcpy((VOID *) (nextPtr->buf + BUFFER_PADDING - extra),
        (VOID *) (raw + gsPtr->rawRead), (size_t) extra);
        nextPtr->nextRemoved -= extra;
        bufPtr->nextAdded -= extra;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Comments:
    
    --'bufPtr' is of type 'ChannelBuffer*'. The structure is
    defined as
    
    typedef struct ChannelBuffer {
    ... some fields omitted
        char buf[4];/* Placeholder for real buffer. The real
                                     * buffer occuppies this space + bufSize-4
                                     * bytes. This must be the last field in
                                     * the structure. */
    } ChannelBuffer;
    
    The system employs a common trick: The structure
    defined here declares just the head of the buffer. In
    the memory the data in the buffer is appended
    immediately behind this head, and the 'buf' field
    gives us an easy to compute reference to it (The
    compiler does it for us, no need to do the pointer
    arithmetics by ourselves).
    
    --The above means that the warning by the compiler is
    correct, the array 'buf' is accessed outside of the
    declared bounds. Still the access is correct and
    nothing can be done (except to completely rewrite the
    buffering system).
    
    This part of the bug is closed.
    
    ___________________________________________________
    (C)cc: Warning: ./../generic/tclIOGT.c, line 174: The
    redefinition of the macro "DELAY" conflicts with a current
    definition because one is object-like and the other is
    function-like.  The redefinition is now in
    effect. (macroredef)
    
        #define DELAY (5)
        --------------^
    
    Comments:
    
    --This part is priority 2, but easy to fix.
    This part is also already fixed in 8.4a2
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /*
    * Number of milliseconds to wait before firing an event to flush
    * out information waiting in buffers (fileevent support).
    */
    
    #define FLUSH_DELAY (5)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ___________________________________________________
    (D)cc: Warning: ./../generic/tclIOSock.c, line 100: In this
    statement, the referenced type of the pointer value "&len" is
    "unsigned long", which is not compatible with "int". (ptrmismatch)
    
            getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&current, &len);
                                                             ---------^
    
    cc: Warning: ./../generic/tclIOSock.c, line 106: In this
    statement, the referenced type of the pointer value "&len" is
    "unsigned long", which is not compatible with "int". (ptrmismatch)
    
            getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&current, &len);
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        /*
         * Should be socklen_t, but HP10.20 (g)cc chokes
         */
        size_t len;
    
    
        len = sizeof(int);
        getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&current, &len);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Comments
    
    --The problem is acknowledged in the code.
    I currently see no way to remedy this.
    Given the platform the bug is reported for
    (Tru64 Unix V5.0a, Alphaserver 8400) this is likely a
    64bit issue.
    
    
    
  2. login: "andreas_kupries"
  3. mimetype: "text/plain"
  4. priority changed to: "8"
  5. subsystem changed to: "57. zlib"
  6. username: "andreas_kupries"