summaryrefslogtreecommitdiffstats
path: root/src/bplist.c
AgeCommit message (Collapse)AuthorFilesLines
2023-02-07Add function to interface to allow enabling/disabling error/debug output for ↵Gravatar Nikias Bassen1-0/+5
the format parses This makes the `-d` option work in plistutil that wasn't doing anything
2023-02-06libcnary: Updated typedefs of node_t and node_list_t to contain pointerGravatar Nikias Bassen1-8/+8
This makes the code more readable. Obviously all the code that uses it is also updated.
2023-01-31bplist: Fix handling of PLIST_NULL node typeGravatar Nikias Bassen1-0/+1
2023-01-16Rename PLIST_UINT to PLIST_INT and add plist_new_int() and plist_get_int_val()Gravatar Nikias Bassen1-12/+12
This properly supports getting and setting signed or unsigned integer values. Also, a new helper function plist_int_val_is_negative() was added to determine if a given #PLIST_INT node has a negative value or not. The old type PLIST_UINT is defined as a macro with the value of PLIST_INT for backwards compatibility. This commit also adds int vs. uint support to the C++ interface, and the python bindings in a hopefully useful way.
2022-09-05Get rid of casting a ptr to a 32 bit valueGravatar Dave MacLachlan1-2/+2
This causes a warning if `-Wbad-function-cast` is enabled on a build.
2022-08-24bplist: Fix strict aliasing violationsGravatar Matthew Smith1-3/+9
Casting a float pointer to an int pointer is a strict aliasing violation (-Wstrict-aliasing) and is undefined behaviour (although, it did not seem to cause any real issues). An optimising compiler should elide the memcopies added by this commit.
2021-12-22Add a return value to plist_to_* and plist_from_* functionsGravatar Nikias Bassen1-15/+45
This way it can be easier determined why an import/export operation failed instead of just having a NULL result.
2021-12-19Add support for PLIST_NULL typeGravatar Nikias Bassen1-0/+12
2021-12-19Add new plist_mem_free() functionGravatar Nikias Bassen1-5/+0
Thanks to @azerg for bringing this to my attention. Instead of having multiple (internally identical) plist_*_free() functions, this commit introduces a single plist_mem_free() that can be used to free the memory allocated by plist_to_xml(), plist_to_bin(), plist_get_key_val(), plist_get_string_val(), and plist_get_data_val(). Note: This commit REMOVES plist_to_bin_free() and plist_to_xml_free().
2020-11-24Add parentheses to macros for better readabilityGravatar Rosen Penev1-14/+14
[clang-tidy] Found with bugprone-macro-parentheses Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-11-21bplist: Fix offset table range check, don't rely on pointer overflowGravatar Nikias Bassen1-1/+1
2020-06-08Remove whitespace errors from all filesGravatar Martin Szulecki1-1/+1
2020-06-03Remove pointless return in void functionsGravatar Rosen Penev1-2/+0
[clang-tidy] Found with readability-redundant-control-flow Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-05-14bplist: Prevent 32bit compiler warningGravatar Nikias Bassen1-1/+3
2020-05-11bplist: Remove unnecessary allocation and unused variablesGravatar Nikias Bassen1-10/+5
2019-12-09bplist: Silence compiler warningGravatar Nikias Bassen1-2/+2
2019-12-09bplist: Add cast to/from uint32_t when reading/storing indices for recursion ↵Gravatar Nikias Bassen1-4/+4
check
2019-12-09bplist: use ptr_array instead of PLIST_ARRAY to store node indices for ↵Gravatar XD1-10/+10
recursing check This improves performance by at least 30% for large files, and also reduces the memory footprint.
2019-11-07Add plist_to_bin_free() and plist_to_xml_free() functions that free memory ↵Gravatar Nikias Bassen1-0/+5
allocated by plist_to_bin()/plist_to_xml()
2019-01-18bplist: Silence compiler warning 'comparison is always true ...' (32 bit)Gravatar Nikias Bassen1-1/+1
2018-12-10Remove node_iterator and operate on node list directly to improve memory usageGravatar Nikias Bassen1-4/+1
2018-12-10bplist: Improve performance and memory usage when writing binary plistGravatar Nikias Bassen1-2/+84
2018-11-30bplist: Remove unnecessary allocations when parsing and writing unicode nodesGravatar Nikias Bassen1-88/+72
2018-11-29bplist: Remove redundant calls to strlen()Gravatar Nikias Bassen1-7/+4
2017-05-31bplist: Prevent store to misaligned address when writing real/date nodesGravatar Nikias Bassen1-9/+9
ASAN reported possible undefined behaviour when writing float/double values to misaligned addresses.
2017-05-29bplist: Work around misaligned reads reported by AddressSanitizerGravatar Nikias Bassen1-3/+3
These misaligned reads reported by ASAN might lead to undefined behavior.
2017-04-20bplist: Fix missing break in switch statement in plist_to_bin()Gravatar Nikias Bassen1-0/+1
Credit to Christophe Fergeau
2017-04-20bplist: Suppress compiler warnings with proper castsGravatar Nikias Bassen1-3/+3
2017-04-19bplist: Fix integer overflow check (offset table size)Gravatar Nikias Bassen1-3/+17
2017-03-26bplist: Make sure sanity checks work on 32bit platformsGravatar Nikias Bassen1-10/+14
Because on 32-bit platforms 32-bit pointers and 64-bit sizes have been used for the sanity checks of the offset table and object references, the range checks would fail in certain interger-overflowish situations, causing heap buffer overflows or other unwanted behavior. Fixed by wideing the operands in question to 64-bit.
2017-02-10bplist: Fix data range check for string/data/dict/array nodesGravatar Nikias Bassen1-6/+6
Passing a size of 0xFFFFFFFFFFFFFFFF to parse_string_node() might result in a memcpy with a size of -1, leading to undefined behavior. This commit makes sure that the actual node data (which depends on the size) is in the range start_of_object..start_of_object+size. Credit to OSS-Fuzz
2017-02-10bplist: Fix integer overflow resulting in OOB heap buffer readGravatar Nikias Bassen1-0/+5
Credit to OSS-Fuzz
2017-02-09bplist: Make sure to detect integer overflow when handling unicode node sizeGravatar Nikias Bassen1-0/+4
Credit to OSS-Fuzz
2017-02-07bplist: Properly handle some more malloc() failure situationsGravatar Nikias Bassen1-3/+18
2017-02-07bplist: Make sure to bail out if malloc() fails in parse_unicode_node()Gravatar Nikias Bassen1-0/+5
Credit to OSS-Fuzz
2017-02-07bplist: Make sure to bail out if malloc() fails in parse_data_node()Gravatar Nikias Bassen1-0/+5
Credit to OSS-Fuzz
2017-02-07bplist: Make sure to bail out if malloc() fails in parse_string_node()Gravatar Nikias Bassen1-0/+5
Credit to Wang Junjie <zhunkibatu@gmail.com> (#93)
2017-02-06bplist: Plug memory leak in case parsing a dictionary key failsGravatar Nikias Bassen1-0/+1
2017-02-06bplist: Refine some debug/error messages in parse_dict_node()Gravatar Nikias Bassen1-4/+4
2017-02-05bplist: Suppress compiler warnings about format specifiers in error messagesGravatar Nikias Bassen1-8/+9
2017-02-05bplist: Add error/debug logging (only if configured with --enable-debug)Gravatar Nikias Bassen1-31/+112
This commit adds proper debug/error messages being printed if the binary plist parser encounters anything abnormal. To enable debug logging, libplist must be configured with --enable-debug, and the environment variable PLIST_BIN_DEBUG must be set to "1".
2017-02-05bplist: Make sure node data is always before the offset tableGravatar Nikias Bassen1-14/+14
2017-02-05bplist: Make sure the offset table is in the correct rangeGravatar Nikias Bassen1-4/+9
2017-02-05bplist: Make sure node index is smaller than number of objectsGravatar Nikias Bassen1-1/+1
2017-02-04bplist: Fix OOB write on heap buffer and improve recursion checkGravatar Nikias Bassen1-8/+14
Issue #92 pointed out an problem with (invalid) bplist files which have exactly one structured node whose subnode reference itself. The recursion check used a fixed size array with the size of the total number of objects. In this case the number of objects is 1 but the recursion check code wanted to set the node_index for the level 1 which leads to an OOB write on the heap. This commit fixes/improves two things: 1) Prevent OOB write by using a dynamic data storage for the used node indexes (plist_t of type PLIST_ARRAY) 2) Reduces the memory usage of large binary plists, because not the total number of nodes in the binary plist, but the number of recursion levels is important for the recursion check.
2017-02-03bplist: Prevent OOB read when parsing data/string/array/dict size nodesGravatar Nikias Bassen1-0/+2
As reported in #91, the code that will read the big endian integer value of variable size did not check if the actual number of bytes is still withing the range of the actual plist data. This commit fixes the issue with proper bounds checking.
2017-02-03bplist: Unify size node parsing for data/string/array/dict nodesGravatar Nikias Bassen1-45/+24
2017-02-01bplist: Fix possible out-of-bounds read in parse_array_node() with proper ↵Gravatar Nikias Bassen1-4/+12
bounds checking
2017-02-01bplist: Avoid heap buffer allocation when parsing array/dict/string/data ↵Gravatar Nikias Bassen1-20/+25
node sizes > 14 The sizes where effectively parsed by calling parse_uint_node() which allocates a node_t (along with plist_data_t) that is immediately freed after retrieving the integer value it holds. This commit changes the code to directly operate on the binary stream to 'just' read the size instead, reducing the memory footprint further.
2017-01-28bplist: Don't duplicate output buffer in plist_to_bin()Gravatar Nikias Bassen1-4/+4