summaryrefslogtreecommitdiffstats
path: root/src/plist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2026-01-20 15:15:17 +0100
committerGravatar Nikias Bassen2026-01-20 15:15:17 +0100
commitc18d6b323e8121c041e8b88d2ea6b6e85ca41274 (patch)
tree2e4007b37eaa8ad6a7a7497c8d36b4c4bd67d077 /src/plist.c
parentcff6a14ba4d0964c4fb4843aad84db12b4df2854 (diff)
downloadlibplist-c18d6b323e8121c041e8b88d2ea6b6e85ca41274.tar.gz
libplist-c18d6b323e8121c041e8b88d2ea6b6e85ca41274.tar.bz2
plist: Fix heap overflow caused by incorrect PLIST_STRING length during copy
Credit to @LkkkLxy. Addresses #277.
Diffstat (limited to 'src/plist.c')
-rw-r--r--src/plist.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/plist.c b/src/plist.c
index 9a488bb..6197e3d 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -581,12 +581,27 @@ static plist_t plist_copy_node(node_t node)
581 node_type = plist_get_node_type(node); 581 node_type = plist_get_node_type(node);
582 switch (node_type) { 582 switch (node_type) {
583 case PLIST_DATA: 583 case PLIST_DATA:
584 newdata->buff = (uint8_t *) malloc(data->length); 584 if (data->buff) {
585 memcpy(newdata->buff, data->buff, data->length); 585 newdata->buff = (uint8_t *) malloc(data->length);
586 assert(newdata->buff);
587 memcpy(newdata->buff, data->buff, data->length);
588 } else {
589 newdata->buff = NULL;
590 newdata->length = 0;
591 }
586 break; 592 break;
587 case PLIST_KEY: 593 case PLIST_KEY:
588 case PLIST_STRING: 594 case PLIST_STRING:
589 newdata->strval = strdup(data->strval); 595 if (data->strval) {
596 size_t n = strlen(data->strval) + 1;
597 newdata->strval = (char*)malloc(n);
598 assert(newdata->strval);
599 memcpy(newdata->strval, data->strval, n);
600 newdata->length = (uint64_t)n;
601 } else {
602 newdata->strval = NULL;
603 newdata->length = 0;
604 }
590 break; 605 break;
591 case PLIST_ARRAY: 606 case PLIST_ARRAY:
592 if (data->hashtable) { 607 if (data->hashtable) {