diff options
author | Florian Frank <flori@ping.de> | 2012-03-21 09:10:35 +0100 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2012-03-21 09:10:35 +0100 |
commit | 59f51d2d1b0b8d390fc4b14dbbd60e189b9280d3 (patch) | |
tree | 885abe21559defa2f73fee49cb81ea0019e88c13 /ext | |
parent | 8fd84e66cafa983b4922208950e4572b4734aa91 (diff) | |
download | json-fix-regex-stack-overflow.tar.gz |
Fix the fixfix-regex-stack-overflow
Diffstat (limited to 'ext')
-rw-r--r-- | ext/json/ext/generator/generator.c | 27 |
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 == '}'; } /* |