aboutsummaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-04-25 19:15:56 +0930
committerMark Pulford <mark@kyne.com.au>2011-04-25 19:15:56 +0930
commit2a12b3fa4b8cdef53288aa2667df0dad2d7f2fc2 (patch)
tree553107e5ad0d580326cea4801b73846e8c0abfe9 /strbuf.c
parent06b42604a44f49e94bad277f87c9024b40a7e491 (diff)
downloadlua-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.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/strbuf.c b/strbuf.c
index 227cb47..44145dd 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -152,9 +152,7 @@ void strbuf_resize(strbuf_t *s, int len)
152 152
153void strbuf_append_mem(strbuf_t *s, const char *c, int len) 153void 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}