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

exit in utf8ncmp if over limit before reading #57

Merged
merged 1 commit into from
Jan 20, 2019

Conversation

bitonic
Copy link
Contributor

@bitonic bitonic commented Jan 20, 2019

this makes the function safe on strings that are not null-terminated.

@sheredom
Copy link
Owner

Hey there - thanks for the contribution! Could you please add a test case that would have failed without this change? Just so that it never regresses again in the future.

@bitonic
Copy link
Contributor Author

bitonic commented Jan 20, 2019

@sheredom it is not trivial to set up a reliable test for this, and the failure mode would be a segfault or similar.

however, if you're running valgrind or something like that on CI in the tests it is easy to make valgrind fail with the previous function, so let me know if this is the case.

@sheredom
Copy link
Owner

Hm interesting! Could you just post a code snippet on this pull request showing the failure then? That way when I get round to adding clang sanitizers or valgrind I should have a test case ready to use 😄

@bitonic
Copy link
Contributor Author

bitonic commented Jan 20, 2019

@sheredom (not tested, but should convey the idea):

  unsigned char *chrs1 = (unsigned char *) malloc(1);
  chrs1[0] = 'a';
  unsigned char *chrs2 = (unsigned char *) malloc(1);
  chrs2[0] = 'a';
  utf8ncmp((void *) chrs1, (void *) chrs2, 1);

before this PR, utf8ncmp will try to read beyond the first char, and in the case above that'd be unsafe.

@sheredom sheredom merged commit 2a7c5bf into sheredom:master Jan 20, 2019
@sheredom
Copy link
Owner

@bitonic thanks for the fix - and for the example! Always happy to have new contributors 😄

@bitonic
Copy link
Contributor Author

bitonic commented Jan 20, 2019 via email

@sheredom
Copy link
Owner

I do not have any benchmarks for that - but if you find it is faster to switch the branches around feel free to submit that PR!

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.

2 participants