Skip to content
  • Junio C Hamano's avatar
    sideband: do not read beyond the end of input · 59a255ae
    Junio C Hamano authored
    
    
    The caller of maybe_colorize_sideband() gives a counted buffer
    <src, n>, but the callee checked src[] as if it were a NUL terminated
    buffer.  If src[] had all isspace() bytes in it, we would have made
    n negative, and then
    
     (1) made number of strncasecmp() calls to see if the remaining
         bytes in src[] matched keywords, reading beyond the end of the
         array (this actually happens even if n does not go negative),
         and/or
    
     (2) called strbuf_add() with negative count, most likely triggering
         the "you want to use way too much memory" error due to unsigned
         integer overflow.
    
    Fix both issues by making sure we do not go beyond &src[n].
    
    In the longer term we may want to accept size_t as parameter for
    clarity (even though we know that a sideband message we are painting
    typically would fit on a line on a terminal and int is sufficient).
    Write it down as a NEEDSWORK comment.
    
    Helped-by: default avatarJonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    59a255ae