Commit graph

17 commits

Author SHA1 Message Date
Mike Dalessio
df4c77608e [ruby/yarp] fix: octal, hex, and unicode strings at the end of a
file
(https://github.com/ruby/yarp/pull/1371)

* refactor: move EOF check into yp_unescape_calculate_difference

parser_lex is a bit more readable when we can rely on that behavior

* fix: octal and hex digits at the end of a file

Previously this resulted in invalid memory access.

* fix: unicode strings at the end of a file

Previously this resulted in invalid memory access.

* Unterminated curly-bracket unicode is a syntax error

21cf11acb5
2023-08-31 22:40:35 +00:00
Mike Dalessio
bbaae3681c [ruby/yarp] fix: regular expression with start and end out of order
Also, a similar test and fix for interpolated regular expressions.

This snippet:

    <<-A.g//,
    A
    /{/, ''\

previously created a regular expression node with inverted start and
end:

    RegularExpressionNode(14...13)((14...15), (15...21), (12...13), ", ''", 0),

which failed an assertion during serialization.

After this change:

    RegularExpressionNode(12...15)((14...15), (15...21), (12...13), ", ''", 0),

Found by the fuzzer.

5fef572f95
2023-08-30 20:46:09 +00:00
Mike Dalessio
6beaf010a4 [ruby/yarp] fix: binary CallNode with out-of-order arg and receiver
The snippet added in this commit previously resulted in a CallNode
with inverted start and end locations:

    >   AssocNode(15...13)(
    >     CallNode(15...13)(
            StringNode(15...17)((15...16), (16...16), (16...17), ""),
            nil,
            (12...13),
            nil,
            ArgumentsNode(12...13)([MissingNode(12...13)()]),
            nil,
            nil,
            0,
            "/"
          ),
          MissingNode(13...13)(),
          (13...13)
        ),

which failed an assertion during serialization.

After this change, it looks better:

    >   AssocNode(12...13)(
    >     CallNode(12...17)(
            StringNode(15...17)((15...16), (16...16), (16...17), ""),
            nil,
            (12...13),
            nil,
            ArgumentsNode(12...13)([MissingNode(12...13)()]),
            nil,
            nil,
            0,
            "/"
          ),
          MissingNode(13...13)(),
          (13...13)
        ),

Found by the fuzzer.

040aa63ad6
2023-08-30 20:46:09 +00:00
Mike Dalessio
f80582cda8 [ruby/yarp] fix: StatementsNode with out-of-order body nodes
The presence of the heredocs in this snippet with invalid syntax:

    for <<A + <<B
    A
    B

causes the MissingNode to have a location after other nodes in the
list, resulting in a StatementsNode with inverted start and end
locations:

      [ForNode(0...14)(
         MultiWriteNode(4...7)([InterpolatedStringNode(4...7)((4...7), [], (14...16))], nil, nil, nil, nil),
         MissingNode(16...16)(),
    >    StatementsNode(16...14)(
           [MissingNode(16...16)(), InterpolatedStringNode(10...13)((10...13), [], (16...18)), MissingNode(13...14)()]
         ),
         (0...3),
         (16...16),
         nil,
         (14...14)
       )]

which failed an assertion during serialization.

With this fix, the node's locations are:

      [ForNode(0...14)(
         MultiWriteNode(4...7)([InterpolatedStringNode(4...7)((4...7), [], (14...16))], nil, nil, nil, nil),
         MissingNode(16...16)(),
    >    StatementsNode(10...16)(
           [MissingNode(16...16)(), InterpolatedStringNode(10...13)((10...13), [], (16...18)), MissingNode(13...14)()]
         ),
         (0...3),
         (16...16),
         nil,
         (14...14)
       )]

Found by the fuzzer.

09bcedc05e
2023-08-30 20:46:08 +00:00
Kevin Newton
cc71e2344b [ruby/yarp] Revisit lex.rake, make lex:rubygems more useable
4c76f4a0c0
2023-08-30 20:42:01 +00:00
Kevin Newton
eac3da173a [ruby/yarp] Fix test-unit API in fuzzer test
d24f62566e
2023-08-30 18:36:38 +00:00
Mike Dalessio
2d009805e7 [ruby/yarp] fix: comment followed by whitespace at end of file
Previously this resulted in invalid memory access.

Found by the fuzzer.

b248553dd6
2023-08-30 18:27:52 +00:00
Mike Dalessio
ae7f907559 [ruby/yarp] fix: heredoc with incomplete escape at end of file
Previously this resulted in invalid memory access.

Found by the fuzzer.

ec4abd87f4
2023-08-30 18:27:51 +00:00
Mike Dalessio
341f47a6dd [ruby/yarp] fix: incomplete escape in regex at the end of file
Previously this resulted in invalid memory access.

Found by the fuzzer.

55b9dfb41c
2023-08-30 18:27:51 +00:00
Mike Dalessio
7cebb9b737 [ruby/yarp] fix: incomplete escape in list at the end of file
Previously this resulted in invalid memory access.

Found by the fuzzer.

78ed75ed75
2023-08-30 18:27:51 +00:00
Mike Dalessio
46e47404a8 [ruby/yarp] fix: trailing decimal, binary, octal, and hex numbers at end of file
Previously this resulted in invalid memory access.

Found by the fuzzer.

af5b85a27a
2023-08-30 18:27:50 +00:00
Mike Dalessio
c83552a596 [ruby/yarp] fix: trailing asterisk at end of file
Previously this resulted in invalid memory access.

Found by the fuzzer.

c86b4907b4
2023-08-30 18:27:49 +00:00
Mike Dalessio
bd0268372e [ruby/yarp] fix: trailing comment at end of file
Previously this resulted in invalid memory access.

Found by the fuzzer.

a1c9404906
2023-08-30 18:27:49 +00:00
Mike Dalessio
6f8126faeb [ruby/yarp] fix: string escape char "\" at the end of a file
Previously this resulted in invalid memory access.

Found by the fuzzer.

178862e2ca
2023-08-30 18:27:48 +00:00
Mike Dalessio
476f38d62d [ruby/yarp] fix: ":" at the end of a file
Previously this resulted in invalid memory access.

Found by the fuzzer.

c781c9fcd2
2023-08-30 18:27:48 +00:00
Mike Dalessio
3da139d284 [ruby/yarp] fix: "$" at the end of a file
Previously this resulted in invalid memory access as well as a
cascading failed assertion:

    src/enc/yp_unicode.c:2224: yp_utf_8_codepoint: Assertion `n >= 1' failed.

Found by the fuzzer.

a34c534440
2023-08-30 18:27:47 +00:00
Mike Dalessio
440cdceffb [ruby/yarp] test: new test file for capturing interesting fuzzer snippets
Note that we call `YARP.dump` for these fuzzer tests to better match
the fuzz.parse harness, which also serializes.

032ad047e9
2023-08-30 18:27:47 +00:00