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

Invalid comparison of strings in dict #2108

Closed
olivier-matz-6wind opened this issue Sep 28, 2023 · 2 comments
Closed

Invalid comparison of strings in dict #2108

olivier-matz-6wind opened this issue Sep 28, 2023 · 2 comments
Labels
is:bug Bug description. status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...)

Comments

@olivier-matz-6wind
Copy link
Contributor

While reading dict's code, I was surprised to see the following test in lydict_val_eq():

if (strncmp(str1, str2, *(size_t *)cb_data) == 0) {
    return 1;
}

*cb_data contains the length of str1, which means that if we compare str1 with (str1 + "something"), it will return true.

This happens rarely because the hash table code already compares the hash, so the string must also have the same hash to trigger the issue. I've setup a unit test that points out this wrong behavior, I'm attaching it.

add_collision_test.patch.txt

I also have 2 draft fixes for this:

Please let me know if I need to do a pull request, thanks!

michalvasko added a commit that referenced this issue Sep 29, 2023
@michalvasko
Copy link
Member

Yes, it should be fixed in libyang devel.

@michalvasko michalvasko added is:bug Bug description. status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...) labels Sep 29, 2023
@olivier-matz-6wind
Copy link
Contributor Author

Thanks for the fix!

I was first surprised by your commit because I tried it myself and unit tests were broken after that.
So just for the record, both commits de17be1 ("dict BUGFIX check whole compared string") and c6a1fe6 ("dict UPDATE avoid comparison of the exact same strings") are actually needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:bug Bug description. status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...)
Projects
None yet
Development

No branches or pull requests

2 participants