Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfl_array: fix memory overlap when removing from array by index. #42

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

pwhelan
Copy link
Contributor

@pwhelan pwhelan commented Apr 3, 2024

This code will fail, at the very least when using ASAn:

    cfl_variant_destroy(array->entries[position]);

    if (position != array->entry_count - 1) {
        memcpy(&array->entries[position],
               &array->entries[position + 1],
               sizeof(void *) * (array->entry_count - (position + 1)));
    }
    else {
        array->entries[position] = NULL;

This is because you will inevitably be copying over the remaining values on top of the value being removed.

This fix just replaces memcpy for memmove which allows for src and dst to overlap.

@edsiper edsiper merged commit c86d8f3 into master Apr 8, 2024
23 checks passed
@edsiper edsiper deleted the pwhelan-cfl-array-fix-mem-overlap-remove-by-index branch April 8, 2024 00:10
@edsiper
Copy link
Member

edsiper commented Apr 8, 2024

thanks

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.

3 participants