Skip to content

Commit

Permalink
fix another segv
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Dec 12, 2017
1 parent db10c28 commit a5c4030
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ext/yajl/yajl_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
str = rb_funcall(obj, intern_to_json, 0);
Check_Type(str, T_STRING);
cptr = RSTRING_PTR(str);
len = (unsigned int)RSTRING_LEN(str);
len = (unsigned int)RSTRING_LEN(str);
CHECK_STATUS(yajl_gen_number(w->encoder, cptr, len));
} else {
str = rb_funcall(obj, intern_to_s, 0);
Check_Type(str, T_STRING);
cptr = RSTRING_PTR(str);
len = (unsigned int)RSTRING_LEN(str);
len = (unsigned int)RSTRING_LEN(str);
CHECK_STATUS(yajl_gen_string(w->encoder, (const unsigned char *)cptr, len));
}
break;
Expand Down Expand Up @@ -861,6 +861,9 @@ static VALUE rb_yajl_projector_build_simple_value(yajl_event_stream_t parser, ya
case yajl_tok_comma:
rb_raise(cParseError, "unexpected comma while constructing value");

case yajl_tok_colon:
rb_raise(cParseError, "unexpected colon while constructing value");

default:;
assert(0);
}
Expand Down
8 changes: 8 additions & 0 deletions spec/projection/projection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
}.to raise_error(Yajl::ParseError)
end

it "should raise an exception and not segv on colons" do
stream = StringIO.new('[::::]')
projector = Yajl::Projector.new(stream)
expect {
projector.project({"name" => nil})
}.to raise_error(Yajl::ParseError)
end

def project(schema, over: "", json: nil, stream: nil)
if stream.nil?
if json.nil?
Expand Down

0 comments on commit a5c4030

Please sign in to comment.