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

zhashx_dup() should use previous hashes comparator and key functions? #2144

Closed
chu11 opened this issue Jan 4, 2021 · 2 comments · Fixed by #2146
Closed

zhashx_dup() should use previous hashes comparator and key functions? #2144

chu11 opened this issue Jan 4, 2021 · 2 comments · Fixed by #2146

Comments

@chu11
Copy link
Contributor

chu11 commented Jan 4, 2021

Recently used zhashx_dup() to copy a hash, leading to an assert in zhashx_insert() while in the middle of the copy iteration in zhashx_dup().

Eventually, I determined the issue was that we use an alternate setting of the key hasher, comparator, duplicator, and destructor. However in zhashx_dup() it does not appear to copy those over. It only copies over the item duplicator/destructor.

    zhashx_t *copy = zhashx_new ();
    if (copy) {
        copy->destructor = self->destructor;
        copy->duplicator = self->duplicator;

I think it should be using the same hasher/key functions across the board?

@bluca
Copy link
Member

bluca commented Jan 4, 2021

Can you send a PR to fix it, please?

@chu11
Copy link
Contributor Author

chu11 commented Jan 4, 2021

@bluca sure

chu11 added a commit to chu11/czmq that referenced this issue Jan 4, 2021
source hash perfectly.  It does not duplicate the source hash's
hasher function, as the well as the key destructor, duplicator,
or comparator.  This minimally can lead to unexpected behavior
of the duplicate zhashx.  At worst it can cause memory corruption,
as the default zhashx key destructor is set to zstr_free().

Solution: Copy the source hasher, key destructor, key duplicator,
and key comparator over to the newly duplicated zhashx.

Fixes zeromq#2144
chu11 added a commit to chu11/czmq that referenced this issue Jan 4, 2021
source hash perfectly.  It does not duplicate the source hash's
hasher function, as the well as the key destructor, duplicator,
or comparator.  This minimally can lead to unexpected behavior
of the duplicate zhashx.  At worst it can cause memory corruption,
as the default zhashx key destructor is set to zstr_free().

Solution: Copy the source hasher, key destructor, key duplicator,
and key comparator over to the newly duplicated zhashx.

Fixes zeromq#2144
chu11 added a commit to chu11/czmq that referenced this issue Jan 4, 2021
The zhashx_dup() function does not duplicate the source hash perfectly.
It does not duplicate the source hash's hasher function, as the well as
the key destructor, duplicator, or comparator.  This minimally can lead
to unexpected behavior of the duplicate zhashx.  At worst it can cause
assert/segfault/memory corruption as zhashx defaults access/free unintended
memory.

Solution: Copy the source hasher, key destructor, key duplicator,
and key comparator over to the newly duplicated zhashx.

Fixes zeromq#2144
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 a pull request may close this issue.

2 participants