Skip to content

memcpy error in buffer_entry.c overflows destination keylen #5

Description

@OpenShooter

The following memcpy() in buffer_entry.c is incorrect:

cmph_uint32 * keylen
[...]
memcpy(keylen + copied_bytes, buffer_entry->buff + buffer_entry->pos, (size_t)lacked_bytes);

Because cmph_uint32 has a length of 4 bytes, pointer arithmetic adds 4 bytes at a time, whereas copied_bytes is measured in bytes.

When copied_bytes is non-zero, the destination address for the memcpy is wrong resulting in stack corruption.

Therefore, it should be

memcpy((cmph_uint8 *)keylen + copied_bytes, buffer_entry->buff + buffer_entry->pos, (size_t)lacked_bytes);

It seems to be wrong in all branches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions