Memmem is not available on Windows.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
@morehouse
Please take a look.
This patch replaces use of memmem with strstr so that the two tests that use this code can compile on Windows (they still fail because LLVMFuzzerInitialize isn't working, but I have a fix for that, patch on the way).
cc @george.karpenkov who switched this to memmem initially.
I'm fine with the change. I don't remember why it was switched initially, probably because the previous version was not working on macOS.
I tried using memcmp and I had to limit the size (to around ~50 chars) or else the test would run forever. I can't say I know exactly why though.
Actually, I think I know why.
It looks like exact match was too difficult for LF (was lit not always used for tests?).
This is why a search function was first added by @george.karpenkov
See
https://github.com/llvm-mirror/llvm/commit/6795f26af554ad58aaca056db03657653b2e4e60#diff-1034b931b86661aee0b11db45658a8b5
That patch broke the behavior of this test. Looks like we used to print "BINGO" when the input matched the binary name. Now we print "BINGO" when the input size matches but the names do not.
It definitely changed the behavior, but I'm not sure it broke it. Since that patch we print BINGO if Data contained argv[0].
Do you want to go back to exact match?
libFuzzer seems to have a hard time with this on any platform (the path names can get extremely long).
Also, being able to pass an exact match doesn't seem to be relevant to the purpose of this test (it seems intended to test that LLVMFuzzerInitialize is called).
Maybe I'm misunderstanding something, but I'm pretty sure memmem returns non-null on a match while strncmp returns 0 on match. Which would mean the ! should have been removed.
Sorry, Matt you had a better understanding of what my patch does than I did.
You are right that the if-body is taken when the lengths are the same but the string is different.
In any case though, I think testing if we can match strings is unnecessary anyway right? Can we just test that argv0 was set?
My first diff did an exact match on part of argv[0], doing the entire thing was too difficult: https://reviews.llvm.org/D51692?vs=on&id=164071&whitespace=ignore-most#toc
Do you think that solution is better than testing if argv0 was set?
That patch broke the behavior of this test
Are you referring to https://reviews.llvm.org/D36242 ?
Yes, it seems it had a bug and ! should have been dropped.
It seems reasonable to just check that argv is set, since this test is intended to check for LLVMFuzzerInitialize being called. There's plenty of other tests where libFuzzer must find a string.
In my newest diff, we enter the if-body if argv0 was set by LLVMFuzzerInitialize and Data begins with "fuzz", which should be easy enough for most any test to pass.
We cant just enter the body if argv0 was set since standalone.test depends on the body not being entered (the print of BINGO causes the test to fail).