commit ea9c030

Saagar Jha  ·  2023-04-10 08:34:48 +0000 UTC
parent 632bbe4
Fix heap overflow from curl-originating buffers

Most of xs.h seems to expect that buffers are rounded up to block size,
so we should preserve that invariant here. (In particular, xs_expand
will avoid calling xs_realloc if the new size fits in the same block,
which means that if we don't pad out the data it will expand out of the
memory we're allocated.)
1 files changed,  +1, -1
+1, -1
1@@ -55,7 +55,7 @@ static int _data_callback(void *buffer, size_t size,
2 
3     /* open space */
4     pd->size += sz;
5-    pd->data = xs_realloc(pd->data, pd->size + 1);
6+    pd->data = xs_realloc(pd->data, _xs_blk_size(pd->size + 1));
7 
8     /* copy data */
9     memcpy(pd->data + pd->offset, buffer, sz);