Skip to content

DoS: Infinite loop in parser when ruby script contains an unclosed heredoc named with empty string #5676

@lopopolo

Description

@lopopolo

Reproduction

MRI

$ ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-darwin21]
$ ruby -e "+<<''&"
-e:1: can't find string "" anywhere before EOF
-e:1: syntax error, unexpected end-of-input
+<<''&
$ ruby -e "<<'DOC'&"
-e:1: can't find string "DOC" anywhere before EOF
-e:1: syntax error, unexpected end-of-input
<<'DOC'&

mruby

$ /usr/local/var/rbenv/versions/mruby-3.0.0/bin/mruby -v
mruby 3.0.0 (2021-03-05)
$ /usr/local/var/rbenv/versions/mruby-3.0.0/bin/mruby -e "+<<''&"
-e:3:0: syntax error, unexpected tHEREDOC_END
^C
$ /usr/local/var/rbenv/versions/mruby-3.0.0/bin/mruby -e "<<'DOC'&"
-e:3:0: can't find heredoc delimiter "DOC" anywhere before EOF
-e:3:0: syntax error, unexpected $end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions