summaryrefslogtreecommitdiff
path: root/src/render.c
diff options
context:
space:
mode:
authorPhil Turnbull <philipturnbull@github.com>2018-02-16 13:25:56 -0500
committerPhil Turnbull <philipturnbull@github.com>2018-02-20 12:25:04 -0500
commite489ba4ccb92af53ea823223481005384fad5e14 (patch)
treec9c703979f23d0ec54c237cb9846f6f05907c26c /src/render.c
parenta5c83d7a426bda38aac838f9815664f6189d3404 (diff)
Check for empty buffer when rendering
For empty documents, `->size` is zero so `renderer.buffer->ptr[renderer.buffer->size - 1]` will cause an out-of-bounds read. Empty buffers always point to the global `cmark_strbuf__initbuf` buffer so we read `cmark_strbuf__initbuf[-1]`.
Diffstat (limited to 'src/render.c')
-rw-r--r--src/render.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/render.c b/src/render.c
index 20dca5f..5abd52e 100644
--- a/src/render.c
+++ b/src/render.c
@@ -171,7 +171,7 @@ char *cmark_render(cmark_node *root, int options, int width,
}
// ensure final newline
- if (renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
+ if (renderer.buffer->size == 0 || renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
cmark_strbuf_putc(renderer.buffer, '\n');
}