Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| libc/fuzzing/string/strstr_fuzz.cpp | ||
|---|---|---|
| 23 | I am not sure if we should use another implementation of strstr to test the real implementation. Instead, can we use strcmp in a brute force manner as strcmp has its own fuzz test. auto result = __llvm_libc::strstr(haystack, needle);
// Because of the construction below, the input for which result is NULL can be tested separately.
// For the rest:
if (strcmp(result, needle) != 0) {
__builtin_trap():
}
auto *haystack_ptr = haystack;
for (;haystack_ptr != result; ++haystack)
if (strcmp(haystack_ptr, needle) == 0) {
// An earlier occurance of needle was missed by strstr.
__builtin_trap();
}
}This is brute force and calls strcmp for every byte, but avoids reimplementing strstr. WDYT? | |
| libc/fuzzing/string/strstr_fuzz.cpp | ||
|---|---|---|
| 23 | PTAL and let me know if this is what you're looking for. I had to make some slight modifications since the result returned will include the rest of the string, and thus strcmp() will not always work. | |
| libc/fuzzing/string/strstr_fuzz.cpp | ||
|---|---|---|
| 23 | Hmm nevermind I need to make some changes to this. | |
| libc/fuzzing/string/strstr_fuzz.cpp | ||
|---|---|---|
| 23 | As discussed, strcmp won't quite work here. Created a helper function that mimics memcmp by comparing each letter up to N. | |
Few nits and questions inline but overall LGTM.
| libc/fuzzing/string/strstr_fuzz.cpp | ||
|---|---|---|
| 21 | LLVM style is to use static functions over anonymous namespaces: https://llvm.org/docs/CodingStandards.html#anonymous-namespaces | |
| 21 | May be call it simple_memcmp. | |
| 64 | data1 should be copied so that we can add the null terminator. But, why should we copy into data2? Can we not use the input directly? | |
| libc/fuzzing/string/strstr_fuzz.cpp | ||
|---|---|---|
| 64 | We can, I mostly did it to show there is no intersection between the two. Fixed so that only one new container is created. | |
clang-tidy: warning: invalid case style for function 'raw_strcmp' [readability-identifier-naming]
not useful
clang-tidy: warning: invalid case style for parameter 'left' [readability-identifier-naming]
not useful
clang-tidy: warning: invalid case style for parameter 'right' [readability-identifier-naming]
not useful
clang-tidy: warning: invalid case style for parameter 'n' [readability-identifier-naming]
not useful