Skip to content

Reject copying userdata with a destructor - #440

Open
Alearner12 wants to merge 1 commit into
vstakhov:masterfrom
Alearner12:fix/431-userdata-copy
Open

Alearner12 wants to merge 1 commit into
vstakhov:masterfrom
Alearner12:fix/431-userdata-copy

Conversation

@Alearner12

Copy link
Copy Markdown

Fixes #431.

ucl_object_copy() duplicates a userdata pointer and destructor into independent wrappers. Copying a heap payload with a free destructor and releasing both wrappers reproduces an ASan double-free in either release order.

Reject copies with a destructor because the API has no payload-clone callback. Preserve non-owning copies and document ucl_object_ref() for sharing ownership. Regressions cover release order, destructor counts, borrowed payloads, allocation failures and nested cleanup.

Validation from the checkout's parent directory:

./libucl-build-patched/tests/test_copy_failure
ctest --test-dir libucl-build-patched --output-on-failure
env ASAN_OPTIONS=detect_leaks=1:halt_on_error=1 UBSAN_OPTIONS=halt_on_error=1 ./libucl-build-patched-asan/tests/test_copy_failure
env ASAN_OPTIONS=detect_leaks=1:halt_on_error=1 UBSAN_OPTIONS=halt_on_error=1 ctest --test-dir libucl-build-patched-asan --output-on-failure

Both focused runs passed; regular CTest passed 21/21. Full ASan/UBSan passed 19/21. The two failures also reproduce on the untouched baseline: a test_schema input-buffer leak and null-pointer arithmetic in test_msgpack_malformed.

Prevent independent wrappers from invoking the same opaque destructor twice.
Preserve non-owning copies and document reference sharing. Extend the copy
regressions to cover payload ownership and failure cleanup.

Fixes vstakhov#431
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ucl_object_copy() of a UCL_USERDATA object runs the destructor twice

1 participant