summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2012-03-21 09:10:35 +0100
committerFlorian Frank <flori@ping.de>2012-03-21 09:10:35 +0100
commit59f51d2d1b0b8d390fc4b14dbbd60e189b9280d3 (patch)
tree885abe21559defa2f73fee49cb81ea0019e88c13
parent8fd84e66cafa983b4922208950e4572b4734aa91 (diff)
downloadjson-fix-regex-stack-overflow.tar.gz
-rw-r--r--ext/json/ext/generator/generator.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index a765486..cfd00b5 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/generator/generator.c
@@ -854,27 +854,12 @@ static VALUE cState_partial_generate(VALUE self, VALUE obj)
static int isArrayOrObject(VALUE string)
{
- char c, *q, *p = RSTRING_PTR(string), *pend = p + RSTRING_LEN(string);
-
- while (p < pend) {
- if (isspace(*p)) {
- p++;
- continue;
- }
- if (*p == '[') c = ']';
- else if (*p == '{') c = '}';
- else return 0;
- q = pend - 1;
- while (q > p) {
- if (isspace(*q)) {
- q--;
- continue;
- }
- if (*q == c) return 1;
- }
- return 0;
- }
- return 0;
+ long string_len = RSTRING_LEN(string);
+ char c, *p = RSTRING_PTR(string), *q = p + string_len - 1;
+ if (string_len < 2) return 0;
+ for (; p < q && isspace(*p); p++);
+ for (; q > p && isspace(*q); q--);
+ return *p == '[' && *q == ']' || *p == '{' && *q == '}';
}
/*