Changeset 28260 in webkit


Ignore:
Timestamp:
Nov 30, 2007 3:43:45 PM (16 years ago)
Author:
eric@webkit.org
Message:

2007-11-30 Eric Seidel <eric@webkit.org>

Reviewed by darin.

PCRE crashes under GuardMalloc
http://bugs.webkit.org/show_bug.cgi?id=16127
check against patternEnd to make sure we don't walk off the end of the string

  • pcre/pcre_compile.cpp: (compile_branch): (calculateCompiledPatternLengthAndFlags):
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r28243 r28260  
    2727
    2828        * pcre/pcre_internal.h: Removed all the UTF-16 helper functions.
     29
     302007-11-30  Eric Seidel  <eric@webkit.org>
     31
     32        Reviewed by darin.
     33       
     34        PCRE crashes under GuardMalloc
     35        http://bugs.webkit.org/show_bug.cgi?id=16127
     36        check against patternEnd to make sure we don't walk off the end of the string
     37
     38        * pcre/pcre_compile.cpp:
     39        (compile_branch):
     40        (calculateCompiledPatternLengthAndFlags):
    2941
    30422007-11-30  Eric Seidel  <eric@webkit.org>
  • trunk/JavaScriptCore/pcre/pcre_compile.cpp

    r28243 r28260  
    198198                const UChar* oldptr = ptr;
    199199                c -= '0';
    200                 while (ptr + 1 < patternEnd && isASCIIDigit(ptr[1]) && c <= bracount)
     200                while ((ptr + 1 < patternEnd) && isASCIIDigit(ptr[1]) && c <= bracount)
    201201                    c = c * 10 + *(++ptr) - '0';
    202202                if (c <= bracount) {
     
    727727*/
    728728
     729static inline bool safelyCheckNextChar(const UChar* ptr, const UChar* patternEnd, UChar expected)
     730{
     731    return ((ptr + 1 < patternEnd) && ptr[1] == expected);
     732}
     733
    729734static bool
    730735compile_branch(int options, int* brackets, uschar** codeptr,
     
    775780    /* Switch on next character until the end of the branch */
    776781   
    777     for (;; ptr++)
    778     {
     782    for (;; ptr++) {
    779783        bool negate_class;
    780784        bool should_flip_negation; /* If a negative special such as \S is used, we should negate the whole class to properly support Unicode. */
     
    865869               
    866870                /* If the first character is '^', set the negation flag and skip it. */
    867                
     871
     872                if (ptr + 1 >= patternEnd)
     873                    return -1;
     874
    868875                if (ptr[1] == '^') {
    869876                    negate_class = true;
     
    893900                 strict here. At the start of the loop, c contains the first byte of the
    894901                 character. */
    895                 while ((c = *(++ptr)) != ']') {
     902
     903                while ((++ptr < patternEnd) && (c = *ptr) != ']') {
    896904                    /* Backslash may introduce a single character, or it may introduce one
    897905                     of the specials, which just set a flag. Escaped items are checked for
     
    963971                     here is treated as a literal. */
    964972                   
    965                     if (ptr[1] == '-' && ptr[2] != ']') {
     973                    if ((ptr + 2 < patternEnd) && ptr[1] == '-' && ptr[2] != ']') {
    966974                        ptr += 2;
    967975                       
     
    10871095                            }
    10881096                        }
    1089                     }
    1090                     else
    1091                        
    1092                     /* Handle a single-byte character */
    1093                     {
     1097                    } else {
     1098                        /* Handle a single-byte character */
    10941099                        classbits[c/8] |= (1 << (c&7));
    10951100                        if (options & IgnoreCaseOption) {
     
    12471252                 repeat type to the non-default. */
    12481253               
    1249                 if (ptr + 1 < patternEnd && ptr[1] == '?') {
     1254                if (safelyCheckNextChar(ptr, patternEnd, '?')) {
    12501255                    repeat_type = 1;
    12511256                    ptr++;
     
    22372242        int minRepeats = 0, maxRepeats = 0;
    22382243        int c = *ptr;
    2239        
     2244
    22402245        item_count++;    /* Is zero for the first non-comment item */
    2241        
     2246
    22422247        switch (c) {
    22432248            /* A backslashed item may be an escaped data character or it may be a
    22442249             character type. */
    2245                
     2250
    22462251            case '\\':
    22472252                c = check_escape(&ptr, patternEnd, &errorcode, bracount, false);
     
    22792284                        compile_block.top_backref = refnum;
    22802285                    length += 2;   /* For single back reference */
    2281                     if (ptr[1] == '{' && is_counted_repeat(ptr+2, patternEnd)) {
    2282                         ptr = read_repeat_counts(ptr+2, &minRepeats, &maxRepeats, &errorcode);
     2286                    if (safelyCheckNextChar(ptr, patternEnd, '{') && is_counted_repeat(ptr + 2, patternEnd)) {
     2287                        ptr = read_repeat_counts(ptr + 2, &minRepeats, &maxRepeats, &errorcode);
    22832288                        if (errorcode)
    22842289                            return -1;
     
    22882293                        else
    22892294                            length += 5;
    2290                         if (ptr[1] == '?')
     2295                        if (safelyCheckNextChar(ptr, patternEnd, '?'))
    22912296                            ptr++;
    22922297                    }
     
    23092314            /* This covers the cases of braced repeats after a single char, metachar,
    23102315             class, or back reference. */
    2311            
     2316
    23122317            case '{':
    23132318                if (!is_counted_repeat(ptr+1, patternEnd))
     
    23342339                }
    23352340               
    2336                 if (ptr[1] == '?')
     2341                if (safelyCheckNextChar(ptr, patternEnd, '?'))
    23372342                    ptr++;      /* Needs no extra length */
    2338                
     2343
    23392344            POSSESSIVE:                     /* Test for possessive quantifier */
    2340                 if (ptr[1] == '+') {
     2345                if (safelyCheckNextChar(ptr, patternEnd, '+')) {
    23412346                    ptr++;
    23422347                    length += 2 + 2 * LINK_SIZE;   /* Allow for atomic brackets */
     
    24122417                       
    24132418                        int d = -1;
    2414                         if (ptr + 1 < patternEnd && ptr[1] == '-') {
     2419                        if (safelyCheckNextChar(ptr, patternEnd, '-')) {
    24152420                            UChar const *hyptr = ptr++;
    2416                             if (ptr + 1 < patternEnd && ptr[1] == '\\') {
     2421                            if (safelyCheckNextChar(ptr, patternEnd, '\\')) {
    24172422                                ptr++;
    24182423                                d = check_escape(&ptr, patternEnd, &errorcode, bracount, true);
     
    24222427                                    d = '\b';        /* backspace */
    24232428                            }
    2424                             else if (ptr + 1 < patternEnd && ptr[1] != ']')
     2429                            else if ((ptr + 1 < patternEnd) && ptr[1] != ']')
    24252430                                d = *++ptr;
    24262431                            if (d < 0)
     
    25222527                     we also need extra for wrapping the whole thing in a sub-pattern. */
    25232528                   
    2524                     if (ptr + 1 < patternEnd && ptr[1] == '{' && is_counted_repeat(ptr+2, patternEnd)) {
     2529                    if (safelyCheckNextChar(ptr, patternEnd, '{') && is_counted_repeat(ptr+2, patternEnd)) {
    25252530                        ptr = read_repeat_counts(ptr+2, &minRepeats, &maxRepeats, &errorcode);
    25262531                        if (errorcode != 0)
     
    25312536                        else
    25322537                            length += 5;
    2533                         if (ptr + 1 < patternEnd && ptr[1] == '+') {
     2538                        if (safelyCheckNextChar(ptr, patternEnd, '+')) {
    25342539                            ptr++;
    25352540                            length += 2 + 2 * LINK_SIZE;
    2536                         } else if (ptr + 1 < patternEnd && ptr[1] == '?')
     2541                        } else if (safelyCheckNextChar(ptr, patternEnd, '?'))
    25372542                            ptr++;
    25382543                    }
     
    25502555                /* Handle special forms of bracket, which all start (? */
    25512556               
    2552                 if (ptr + 1 < patternEnd && ptr[1] == '?') {
     2557                if (safelyCheckNextChar(ptr, patternEnd, '?')) {
    25532558                    switch (c = (ptr + 2 < patternEnd ? ptr[2] : 0)) {
    25542559                            /* Non-referencing groups and lookaheads just move the pointer on, and
     
    26222627                 automatically; for the others we need an increment. */
    26232628               
    2624                 if (ptr + 1 < patternEnd && (c = ptr[1]) == '{' && is_counted_repeat(ptr+2, patternEnd)) {
     2629                if ((ptr + 1 < patternEnd) && (c = ptr[1]) == '{' && is_counted_repeat(ptr+2, patternEnd)) {
    26252630                    ptr = read_repeat_counts(ptr+2, &minRepeats, &maxRepeats, &errorcode);
    26262631                    if (errorcode)
     
    26682673                /* Allow space for once brackets for "possessive quantifier" */
    26692674               
    2670                 if (ptr + 1 < patternEnd && ptr[1] == '+') {
     2675                if (safelyCheckNextChar(ptr, patternEnd, '+')) {
    26712676                    ptr++;
    26722677                    length += 2 + 2 * LINK_SIZE;
  • trunk/LayoutTests/ChangeLog

    r28247 r28260  
     12007-11-30  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by darin.
     4       
     5        Test case for:
     6        http://bugs.webkit.org/show_bug.cgi?id=16127
     7
     8        * fast/js/regexp-compile-crash-expected.txt: Added.
     9        * fast/js/regexp-compile-crash.html: Added.
     10
    1112007-11-30  Adam Roben  <aroben@apple.com>
    212
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r28258 r28260  
    1410814108                        isa = PBXProject;
    1410914109                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
     14110                        compatibilityVersion = "Xcode 2.4";
    1411014111                        hasScannedForEncodings = 1;
    1411114112                        knownRegions = (
Note: See TracChangeset for help on using the changeset viewer.