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

bug fix: new ares_strsplit #492

Merged
merged 2 commits into from
Dec 13, 2022
Merged

bug fix: new ares_strsplit #492

merged 2 commits into from
Dec 13, 2022

Conversation

createyourpersonalaccount
Copy link
Contributor

The first commit adds a unit test that reveals a bug in ares_strsplit and the second commit fixes the algorithm.

The test reveals a bug in the implementation of ares_strsplit when the
make_set parameter is set to 1, as distinct domains are confused for
equal:

  out = ares_strsplit("example.com, example.co", ", ", 1, &n);

evaluates to n = 1 with out = { "example.com" }.
The purpose of ares_strsplit in c-ares is to split a comma-delimited
string of unique (up to letter case) domains. However, because the
terminating NUL byte was not checked in the substrings when comparing
for uniqueness, the function would sometimes drop domains it should
not. For example,

    ares_strsplit("example.com, example.co", ",")

would only result in a single domain "example.com".

Aside from this bugfix, the following cleanup is performed:

1. The tokenization now happens with the help of strcspn instead of the
   custom function is_delim.
2. The function list_contains has been inlined.
3. The interface of ares_strsplit has been simplified by removing the
   parameter make_set since in practice it was always 1.
4. There are fewer passes over the input string.
5. We resize the table using realloc() down to its minimum size.
6. The docstring of ares_strsplit is updated and also a couple typos
   are fixed.

There occurs a single use of ares_strsplit and since the make_set
parameter has been removed, the call in ares_init.c is modified
accordingly. The unit test for ares_strsplit is also updated.
@bradh352 bradh352 merged commit 313bd2a into c-ares:main Dec 13, 2022
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