[PATCH] D30384: [asan] Add an interceptor for strtok
Yury Gribov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 28 01:33:52 PST 2017
ygribov added a comment.
> However, I think I have not yet understood why using strict_strings should only verify the string until the first delimiter.
I actually learned this lesson the hard way. C/C++ standards require arguments of standard string functions (`strcpy, `strchr`, etc.) to be strings i.e. zero-terminated arrays. But unfortunately a lot of existing code seems to ignore this rule and also call string functions on arbitrary C arrays. For example
char a[10];
memcpy(a, "11112", 5); // Non-zero terminated
strchr(a, '2'); // Works in practice, even though a isn't a string, because strchr only checks first 5 chars
By default we'd like to not warn about uninteresting errors so we only check string prefix (unless user explicitly asks us with `strict_strings` runtime flag).
> If I select the passed n to be smaller than strlen(str) + 1 then the test case fails, since it does not detect the overflow. What did I understand wrong?
Yes, I guess the test needs to be updated. You can take a look at how other string tests are done (e.g. `test/asan/TestCases//strstr*.c`, you'll probly need `__asan_poison_memory_region` hack).
https://reviews.llvm.org/D30384
More information about the llvm-commits
mailing list