diff options
| author | 2026-05-22 15:00:16 +0200 | |
|---|---|---|
| committer | 2026-05-22 15:00:16 +0200 | |
| commit | 9d4f14a0ba93dc39d516b5e1c1cd107693b81629 (patch) | |
| tree | 5b11003763da40aff38d607d31a0e7f6f3f013da /src/out-limd.c | |
| parent | d35b31d0a2661b6346a1592a5eb7b70e66b2a141 (diff) | |
| download | libplist-9d4f14a0ba93dc39d516b5e1c1cd107693b81629.tar.gz libplist-9d4f14a0ba93dc39d516b5e1c1cd107693b81629.tar.bz2 | |
out-limd: Fix memory buffer allocation size (#313)
Credit to @Bri1987
Diffstat (limited to 'src/out-limd.c')
| -rw-r--r-- | src/out-limd.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/out-limd.c b/src/out-limd.c index 35247fb..8d42c9d 100644 --- a/src/out-limd.c +++ b/src/out-limd.c @@ -190,17 +190,23 @@ static plist_err_t node_to_string(node_t node, bytearray_t **outbuf, uint32_t de } break; case PLIST_DATA: { - val = (char*)malloc(4096); +#define BASE64_CHUNK_SIZE 3072 +#define BASE64_BUF_SIZE (4 * ((BASE64_CHUNK_SIZE + 2) / 3) + 4) + val = (char*)malloc(BASE64_BUF_SIZE); + if (!val) return PLIST_ERR_NO_MEM; size_t done = 0; while (done < node_data->length) { size_t amount = node_data->length - done; - if (amount > 3072) { - amount = 3072; + if (amount > BASE64_CHUNK_SIZE) { + amount = BASE64_CHUNK_SIZE; } size_t bsize = base64encode(val, node_data->buff + done, amount); str_buf_append(*outbuf, val, bsize); done += amount; } + free(val); +#undef BASE64_CHUNK_SIZE +#undef BASE64_BUF_SIZE } break; case PLIST_DATE: |
