Skip to content

Commit 3f0a830

Browse files
phirsovthiagomacieira
authored andcommitted
Fix off-by-one causing buffer overflow in open_memstream
Fixes #140 Signed-off-by: phirsov <[email protected]>
1 parent d072f46 commit 3f0a830

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/open_memstream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static RetType write_to_buffer(void *cookie, const char *data, LenType len)
6464
if (unlikely(add_check_overflow(*b->len, len, &newsize)))
6565
return -1;
6666

67-
if (newsize > b->alloc) {
67+
if (newsize >= b->alloc) { // NB! one extra byte is needed to avoid buffer overflow at close_buffer
6868
// make room
6969
size_t newalloc = newsize + newsize / 2 + 1; // give 50% more room
7070
ptr = realloc(ptr, newalloc);

0 commit comments

Comments
 (0)