summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2022-07-14 09:39:25 -0700
committerGitHub <noreply@github.com>2022-07-14 09:39:25 -0700
commit74fb0be6a07b0564ed58430efc3dc38a60411b63 (patch)
tree7bdbc66bba77bf295f99d05363af5793001cbfb8 /ext
parent251289ba835294d454f20cd0e75bfa1ccb618e6b (diff)
parent6c56700fb270527fb0b88f110de145f769d1c73b (diff)
downloadpsych-74fb0be6a07b0564ed58430efc3dc38a60411b63.tar.gz
Merge pull request #526 from khanderson/master
Fix infinite loop bug after YAML_MEMORY_ERROR (psych issue #440)
Diffstat (limited to 'ext')
-rw-r--r--ext/psych/psych_parser.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/ext/psych/psych_parser.c b/ext/psych/psych_parser.c
index fd550b6..f91475b 100644
--- a/ext/psych/psych_parser.c
+++ b/ext/psych/psych_parser.c
@@ -79,21 +79,25 @@ static VALUE allocate(VALUE klass)
static VALUE make_exception(yaml_parser_t * parser, VALUE path)
{
- size_t line, column;
- VALUE ePsychSyntaxError;
+ if (parser->error == YAML_MEMORY_ERROR) {
+ return rb_eNoMemError;
+ } else {
+ size_t line, column;
+ VALUE ePsychSyntaxError;
- line = parser->context_mark.line + 1;
- column = parser->context_mark.column + 1;
+ line = parser->context_mark.line + 1;
+ column = parser->context_mark.column + 1;
- ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
+ ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
- return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
- path,
- SIZET2NUM(line),
- SIZET2NUM(column),
- SIZET2NUM(parser->problem_offset),
- parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
- parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
+ return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
+ path,
+ SIZET2NUM(line),
+ SIZET2NUM(column),
+ SIZET2NUM(parser->problem_offset),
+ parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
+ parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
+ }
}
static VALUE transcode_string(VALUE src, int * parser_encoding)
@@ -293,7 +297,7 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
VALUE event_args[5];
VALUE start_line, start_column, end_line, end_column;
- if(!yaml_parser_parse(parser, &event)) {
+ if(parser->error || !yaml_parser_parse(parser, &event)) {
VALUE exception;
exception = make_exception(parser, path);