Skip to content
  • Paolo Bonzini's avatar
    avoid exponential regex match for java and objc function names · 959e2e64
    Paolo Bonzini authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    In the old regex
    
    ^[ \t]*(([ \t]*[A-Za-z_][A-Za-z_0-9]*){2,}[ \t]*\([^;]*)$
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    you can backtrack arbitrarily from [A-Za-z_0-9]* into [A-Za-z_], thus
    causing an exponential number of backtracks.  Ironically it also causes
    the regex not to work as intended; for example "catch" can match the
    underlined part of the regex, the first repetition matching "c" and
    the second matching "atch".
    
    The replacement regex avoids this problem, because it makes sure that
    at least a space/tab is eaten on each repetition.  In other words,
    a suffix of a repetition can never be a prefix of the next repetition.
    
    Signed-off-by: Paolo Bonzini's avatarPaolo Bonzini <bonzini@gnu.org>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    959e2e64