summaryrefslogtreecommitdiffstats
path: root/src/bplist.c
diff options
context:
space:
mode:
authorGravatar Comtea042026-09-27 15:06:22 +0900
committerGravatar Nikias Bassen2026-09-29 16:39:28 +0200
commitf168c10b52325b00da6355989a18a11743b33f89 (patch)
tree186ef3afe45963fcfca15daf8efebf0f2151360e /src/bplist.c
parent8b48fa72d359de89215f50cbf6ac8c77ae5de9b4 (diff)
downloadlibplist-f168c10b52325b00da6355989a18a11743b33f89.tar.gz
libplist-f168c10b52325b00da6355989a18a11743b33f89.tar.bz2
bytearray: Handle realloc() failure in byte_array_grow()
byte_array_grow() assigned the result of realloc() directly to ba->data and increased the capacity even if realloc() failed, so the following memcpy() in byte_array_append() wrote to NULL + len. On failure, free the old buffer and leave the byte array in a failed state (data == NULL), which byte_array_append() already ignores. The callers check for that state: - the writers (bin, xml, json, openstep and the text output formats) return PLIST_ERR_NO_MEM instead of handing out a NULL/truncated buffer - node_to_xml() base64-encodes <data> directly into the grown buffer, so it must bail out there (only guarded by assert() before) - the OpenStep parser returns PLIST_ERR_NO_MEM for <hex data> instead of silently returning truncated data Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/bplist.c')
-rw-r--r--src/bplist.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/bplist.c b/src/bplist.c
index ea829c7..8168572 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -1612,6 +1612,13 @@ plist_err_t plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
byte_array_append(bplist_buff, &trailer, sizeof(bplist_trailer_t));
+ if (!bplist_buff->data) {
+ byte_array_free(bplist_buff);
+ *plist_bin = NULL;
+ *length = 0;
+ return PLIST_ERR_NO_MEM;
+ }
+
//set output buffer and size
*plist_bin = (char*)bplist_buff->data;
*length = bplist_buff->len;