diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-04-25 19:15:56 +0930 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-04-25 19:15:56 +0930 |
commit | 2a12b3fa4b8cdef53288aa2667df0dad2d7f2fc2 (patch) | |
tree | 553107e5ad0d580326cea4801b73846e8c0abfe9 /strbuf.c | |
parent | 06b42604a44f49e94bad277f87c9024b40a7e491 (diff) | |
download | lua-cjson-2a12b3fa4b8cdef53288aa2667df0dad2d7f2fc2.tar.gz lua-cjson-2a12b3fa4b8cdef53288aa2667df0dad2d7f2fc2.tar.bz2 lua-cjson-2a12b3fa4b8cdef53288aa2667df0dad2d7f2fc2.zip |
Grow decode stack, prealloc strings during encode
- Check stack usage during decode to prevent crashing in excessively
nested data structures.
- Preallocate the required memory for json_append_string().
Diffstat (limited to 'strbuf.c')
-rw-r--r-- | strbuf.c | 4 |
1 files changed, 1 insertions, 3 deletions
@@ -152,9 +152,7 @@ void strbuf_resize(strbuf_t *s, int len) | |||
152 | 152 | ||
153 | void strbuf_append_mem(strbuf_t *s, const char *c, int len) | 153 | void strbuf_append_mem(strbuf_t *s, const char *c, int len) |
154 | { | 154 | { |
155 | if (len > strbuf_empty_length(s)) | 155 | strbuf_ensure_empty_length(s, len); |
156 | strbuf_resize(s, s->length + len); | ||
157 | |||
158 | memcpy(s->buf + s->length, c, len); | 156 | memcpy(s->buf + s->length, c, len); |
159 | s->length += len; | 157 | s->length += len; |
160 | } | 158 | } |