[ruby/psych] Fix infinite loop bug after YAML_MEMORY_ERROR (psych issue #440)
https://github.com/ruby/psych/commit/6c56700fb2
This commit is contained in:
parent
a5471b616d
commit
509d0a9299
@ -79,21 +79,25 @@ static VALUE allocate(VALUE klass)
|
|||||||
|
|
||||||
static VALUE make_exception(yaml_parser_t * parser, VALUE path)
|
static VALUE make_exception(yaml_parser_t * parser, VALUE path)
|
||||||
{
|
{
|
||||||
size_t line, column;
|
if (parser->error == YAML_MEMORY_ERROR) {
|
||||||
VALUE ePsychSyntaxError;
|
return rb_eNoMemError;
|
||||||
|
} else {
|
||||||
|
size_t line, column;
|
||||||
|
VALUE ePsychSyntaxError;
|
||||||
|
|
||||||
line = parser->context_mark.line + 1;
|
line = parser->context_mark.line + 1;
|
||||||
column = parser->context_mark.column + 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,
|
return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
|
||||||
path,
|
path,
|
||||||
SIZET2NUM(line),
|
SIZET2NUM(line),
|
||||||
SIZET2NUM(column),
|
SIZET2NUM(column),
|
||||||
SIZET2NUM(parser->problem_offset),
|
SIZET2NUM(parser->problem_offset),
|
||||||
parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
|
parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
|
||||||
parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
|
parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE transcode_string(VALUE src, int * parser_encoding)
|
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 event_args[5];
|
||||||
VALUE start_line, start_column, end_line, end_column;
|
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;
|
VALUE exception;
|
||||||
|
|
||||||
exception = make_exception(parser, path);
|
exception = make_exception(parser, path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user