summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-11 02:01:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-11 02:01:36 +0000
commite5c516c89a62839fd025ae112041ed9a5f06c9d0 (patch)
tree5457f6e76dcfa0d9f0dd2f84ad68036fb6c297ab
parent4068d9089adca488546c7ff8b59118eb47a3ade0 (diff)
generator.c: fix infinite recursion
* ext/json/generator/generator.c (generate_json): get rid of unnecessary recursive calls which can cause infinite recursion. T_STRING may not have rb_cString. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/json/generator/generator.c2
-rwxr-xr-xtest/json/test_json_generate.rb10
3 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f2ba38..98c376d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Feb 11 11:01:33 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/json/generator/generator.c (generate_json): get rid of
+ unnecessary recursive calls which can cause infinite recursion.
+ T_STRING may not have rb_cString.
+
Wed Feb 11 07:53:35 2015 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* test/win32ole/test_word.rb: use skip method to skip test.
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 7805cde..9641ecb 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -880,7 +880,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
} else {
tmp = rb_funcall(obj, i_to_s, 0);
Check_Type(tmp, T_STRING);
- generate_json(buffer, Vstate, state, tmp);
+ generate_json_string(buffer, Vstate, state, tmp);
}
}
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb
index 8db0b78..1834290 100755
--- a/test/json/test_json_generate.rb
+++ b/test/json/test_json_generate.rb
@@ -334,4 +334,14 @@ EOT
assert_equal true, JSON.generate(["\xea"])
end
end
+
+ def test_string_subclass
+ s = Class.new(String) do
+ def to_s; self; end
+ undef to_json
+ end
+ assert_nothing_raised(SystemStackError) do
+ assert_equal '[""]', JSON.generate([s.new])
+ end
+ end
end