diff options
Diffstat (limited to 'ext/json/generator')
-rw-r--r-- | ext/json/generator/depend | 6 | ||||
-rw-r--r-- | ext/json/generator/generator.c | 30 |
2 files changed, 20 insertions, 16 deletions
diff --git a/ext/json/generator/depend b/ext/json/generator/depend index 82946d1097..1a042a2501 100644 --- a/ext/json/generator/depend +++ b/ext/json/generator/depend @@ -1,5 +1 @@ -generator.o: generator.c $(HDRS) $(ruby_headers) $(srcdir)/../fbuffer/fbuffer.h \ - $(hdrdir)/ruby/encoding.h \ - $(hdrdir)/ruby/oniguruma.h \ - $(hdrdir)/ruby/re.h \ - $(hdrdir)/ruby/regex.h \ +generator.o: generator.c generator.h $(srcdir)/../fbuffer/fbuffer.h diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c index 40c9e1e6df..ed7bb82887 100644 --- a/ext/json/generator/generator.c +++ b/ext/json/generator/generator.c @@ -273,7 +273,18 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string) escape_len = 2; break; default: - end++; + { + unsigned short clen = trailingBytesForUTF8[c] + 1; + if (end + clen > len) { + rb_raise(rb_path2class("JSON::GeneratorError"), + "partial character in source, but hit end"); + } + if (!isLegalUTF8((UTF8 *) p, clen)) { + rb_raise(rb_path2class("JSON::GeneratorError"), + "source sequence is illegal/malformed utf-8"); + } + end += clen; + } continue; break; } @@ -288,7 +299,7 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string) static char *fstrndup(const char *ptr, unsigned long len) { char *result; - if (len == 0) return NULL; + if (len <= 0) return NULL; result = ALLOC_N(char, len); memccpy(result, ptr, 0, len); return result; @@ -511,11 +522,8 @@ static VALUE cState_configure(VALUE self, VALUE opts) { VALUE tmp; GET_STATE(self); - tmp = rb_convert_type(opts, T_HASH, "Hash", "to_hash"); + tmp = rb_check_convert_type(opts, T_HASH, "Hash", "to_hash"); if (NIL_P(tmp)) tmp = rb_convert_type(opts, T_HASH, "Hash", "to_h"); - if (NIL_P(tmp)) { - rb_raise(rb_eArgError, "opts has to be hash like or convertable into a hash"); - } opts = tmp; tmp = rb_hash_aref(opts, ID2SYM(i_indent)); if (RTEST(tmp)) { @@ -1178,11 +1186,11 @@ static VALUE cState_array_nl_set(VALUE self, VALUE array_nl) /* - * call-seq: check_circular? - * - * Returns true, if circular data structures should be checked, - * otherwise returns false. - */ +* call-seq: check_circular? +* +* Returns true, if circular data structures should be checked, +* otherwise returns false. +*/ static VALUE cState_check_circular_p(VALUE self) { GET_STATE(self); |