Changeset 108841 in webkit


Ignore:
Timestamp:
Feb 24, 2012 1:10:36 PM (12 years ago)
Author:
barraclough@apple.com
Message:

Should not allow malformed \x escapes
https://bugs.webkit.org/show_bug.cgi?id=79462

Reviewed by Oliver Hunt.

Source/JavaScriptCore:

  • parser/Lexer.cpp:

(JSC::::parseString):
(JSC::::parseStringSlowCase):

  • Prohibit malformed '\x' escapes
  • tests/mozilla/ecma/Array/15.4.5.1-1.js:
  • tests/mozilla/ecma/LexicalConventions/7.7.4.js:
  • tests/mozilla/ecma_2/RegExp/hex-001.js:
  • tests/mozilla/js1_2/regexp/hexadecimal.js:
    • Remove erroneous test cases (correct behaviour is tested by LayoutTests/sputnik).

LayoutTests:

  • fast/regex/script-tests/pcre-test-1.js:
    • Fix bad escapes in test case.
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A4.3_T6-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.1_T4-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.2_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.2_T2-expected.txt:
    • Check in passing results.
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r108839 r108841  
     12012-02-24  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Should not allow malformed \x escapes
     4        https://bugs.webkit.org/show_bug.cgi?id=79462
     5
     6        Reviewed by Oliver Hunt.
     7
     8        * fast/regex/script-tests/pcre-test-1.js:
     9            - Fix bad escapes in test case.
     10        * sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A4.3_T6-expected.txt:
     11        * sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.1_T4-expected.txt:
     12        * sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.2_T1-expected.txt:
     13        * sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.2_T2-expected.txt:
     14            - Check in passing results.
     15
    1162012-02-24  Adrienne Walker  <enne@google.com>
    217
  • trunk/LayoutTests/fast/regex/script-tests/pcre-test-1.js

    r98407 r108841  
    10371037var results = null;
    10381038shouldBe('regex68.exec(input2);', 'results');
    1039 var input3 = "A\0\x0\0\x0Z";
     1039var input3 = "A\0\0\0\0Z";
    10401040var results = null;
    10411041shouldBe('regex68.exec(input3);', 'results');
  • trunk/LayoutTests/sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A4.3_T6-expected.txt

    r58534 r108841  
     1CONSOLE MESSAGE: line 77: SyntaxError: \x can only be followed by a hex character sequence
    12S7.8.4_A4.3_T6
    23
    3 FAIL No error detected
     4PASS Expected parsing failure
    45
    56TEST COMPLETE
  • trunk/LayoutTests/sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.1_T4-expected.txt

    r58534 r108841  
     1CONSOLE MESSAGE: line 77: SyntaxError: \x can only be followed by a hex character sequence
    12S7.8.4_A6.1_T4
    23
    3 FAIL No error detected
     4PASS Expected parsing failure
    45
    56TEST COMPLETE
  • trunk/LayoutTests/sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.2_T1-expected.txt

    r58534 r108841  
     1CONSOLE MESSAGE: line 77: SyntaxError: \x can only be followed by a hex character sequence
    12S7.8.4_A6.2_T1
    23
    3 FAIL No error detected
     4PASS Expected parsing failure
    45
    56TEST COMPLETE
  • trunk/LayoutTests/sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A6.2_T2-expected.txt

    r58534 r108841  
     1CONSOLE MESSAGE: line 77: SyntaxError: \x can only be followed by a hex character sequence
    12S7.8.4_A6.2_T2
    23
    3 FAIL No error detected
     4PASS Expected parsing failure
    45
    56TEST COMPLETE
  • trunk/Source/JavaScriptCore/ChangeLog

    r108820 r108841  
     12012-02-24  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Should not allow malformed \x escapes
     4        https://bugs.webkit.org/show_bug.cgi?id=79462
     5
     6        Reviewed by Oliver Hunt.
     7
     8        * parser/Lexer.cpp:
     9        (JSC::::parseString):
     10        (JSC::::parseStringSlowCase):
     11            - Prohibit malformed '\x' escapes
     12        * tests/mozilla/ecma/Array/15.4.5.1-1.js:
     13        * tests/mozilla/ecma/LexicalConventions/7.7.4.js:
     14        * tests/mozilla/ecma_2/RegExp/hex-001.js:
     15        * tests/mozilla/js1_2/regexp/hexadecimal.js:
     16            - Remove erroneous test cases (correct behaviour is tested by LayoutTests/sputnik).
     17
    1182012-02-24  Daniel Bates  <dbates@webkit.org>
    219
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r108742 r108841  
    693693            else if (m_current == 'x') {
    694694                shift();
    695                 if (isASCIIHexDigit(m_current) && isASCIIHexDigit(peek(1))) {
    696                     int prev = m_current;
    697                     shift();
    698                     if (shouldBuildStrings)
    699                         record8(convertHex(prev, m_current));
    700                     shift();
    701                 } else if (shouldBuildStrings)
    702                     record8('x');
     695                if (!isASCIIHexDigit(m_current) || !isASCIIHexDigit(peek(1))) {
     696                    m_lexErrorMessage = "\\x can only be followed by a hex character sequence";
     697                    return false;
     698                }
     699                int prev = m_current;
     700                shift();
     701                if (shouldBuildStrings)
     702                    record8(convertHex(prev, m_current));
     703                shift();
    703704            } else {
    704705                setOffset(startingOffset);
     
    757758            else if (m_current == 'x') {
    758759                shift();
    759                 if (isASCIIHexDigit(m_current) && isASCIIHexDigit(peek(1))) {
    760                     int prev = m_current;
    761                     shift();
    762                     if (shouldBuildStrings)
    763                         record16(convertHex(prev, m_current));
    764                     shift();
    765                 } else if (shouldBuildStrings)
    766                     record16('x');
     760                if (!isASCIIHexDigit(m_current) || !isASCIIHexDigit(peek(1))) {
     761                    m_lexErrorMessage = "\\x can only be followed by a hex character sequence";
     762                    return false;
     763                }
     764                int prev = m_current;
     765                shift();
     766                if (shouldBuildStrings)
     767                    record16(convertHex(prev, m_current));
     768                shift();
    767769            } else if (m_current == 'u') {
    768770                shift();
  • trunk/Source/JavaScriptCore/tests/mozilla/ecma/Array/15.4.5.1-1.js

    r16542 r108841  
    105105
    106106    for ( var i = 0X0020, TEST_STRING = "var A = new Array( " ; i < 0x00ff; i++ ) {
     107        if ( i === 0x58 || i === 0x78 ) // x or X - skip testing invalid hex escapes.
     108            continue;
    107109        TEST_STRING += "\'\\"+ String.fromCharCode( i ) +"\'";
    108110        if ( i < 0x00FF - 1   ) {
     
    113115    }
    114116
    115     var LENGTH = 0x00ff - 0x0020;
     117    var LENGTH = 0x00ff - 0x0020 - 2; // x & X
    116118
    117119    array[item++] = new TestCase(   SECTION,
  • trunk/Source/JavaScriptCore/tests/mozilla/ecma/LexicalConventions/7.7.4.js

    r53061 r108841  
    171171
    172172    // G is out of hex range
    173 
    174     array[item++] = new TestCase( SECTION, "\\xG",        "xG",                                 "\xG" );
    175     array[item++] = new TestCase( SECTION, "\\xCG",       "xCG",                                "\xCG" );
     173// Invalid hex escapes are syntax error; these are covered in the sputnik test suite.
     174//    array[item++] = new TestCase( SECTION, "\\xG",        "xG",                                 "\xG" );
     175//    array[item++] = new TestCase( SECTION, "\\xCG",       "xCG",                                      "\xCG" );
    176176
    177177    // DoubleStringCharacter::EscapeSequence::CharacterEscapeSequence::\ NonEscapeCharacter
     
    194194
    195195    array[item++] = new TestCase( SECTION, "\\w",    "w",        "\w" );
    196     array[item++] = new TestCase( SECTION, "\\x",    "x",        "\x" );
     196// Invalid hex escapes are syntax error; these are covered in the sputnik test suite.
     197//    array[item++] = new TestCase( SECTION, "\\x",    "x",        "\x" );
    197198    array[item++] = new TestCase( SECTION, "\\y",    "y",        "\y" );
    198199    array[item++] = new TestCase( SECTION, "\\z",    "z",        "\z" );
  • trunk/Source/JavaScriptCore/tests/mozilla/ecma_2/RegExp/hex-001.js

    r11995 r108841  
    1717    AddRegExpCases( new RegExp("\x41"),  "new RegExp('\\x41')",  "A",  "A", 1, 0, ["A"] );
    1818    AddRegExpCases( new RegExp("\x412"),"new RegExp('\\x412')", "A2", "A2", 1, 0, ["A2"] );
    19     AddRegExpCases( new RegExp("\x1g"), "new RegExp('\\x1g')",  "x1g","x1g", 1, 0, ["x1g"] );
     19// Invalid hex escapes are syntax error; these are covered in the sputnik test suite.
     20//    AddRegExpCases( new RegExp("\x1g"), "new RegExp('\\x1g')",  "x1g","x1g", 1, 0, ["x1g"] );
    2021
    2122    AddRegExpCases( new RegExp("A"),  "new RegExp('A')",  "\x41",  "\\x41",  1, 0, ["A"] );
  • trunk/Source/JavaScriptCore/tests/mozilla/js1_2/regexp/hexadecimal.js

    r53061 r108841  
    3131        var VERSION = 'no version';
    3232    startTest();
    33         var TITLE   = 'RegExp: \x# (hex) ';
     33        var TITLE   = 'RegExp: \\x# (hex) ';
    3434
    3535        writeHeaderToLog('Executing script: hexadecimal.js');
Note: See TracChangeset for help on using the changeset viewer.