This is an archive of the discontinued LLVM Phabricator instance.

[libfuzzer] add test of cov file-id in control file
ClosedPublic

Authored by yingcong-wu on Mar 9 2023, 1:17 AM.

Details

Summary

There is test for ft file-id in control file, but no test for cov line.
Without the test, a invalid cov file-id would cause crash.

Diff Detail

Event Timeline

yingcong-wu created this revision.Mar 9 2023, 1:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2023, 1:17 AM
Herald added a subscriber: Enna1. · View Herald Transcript
yingcong-wu requested review of this revision.Mar 9 2023, 1:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2023, 1:17 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

add a comment to test

Hi all, kindly ping.

vitalybuka added inline comments.Mar 20 2023, 1:33 PM
compiler-rt/lib/fuzzer/FuzzerMerge.cpp
113

this one is LGTM, and I see the test

123

but i am not sure what this condition for, and I guess it's not covered by test?
maybe it would be easier to understand with a test.

yingcong-wu added inline comments.Mar 20 2023, 6:25 PM
compiler-rt/lib/fuzzer/FuzzerMerge.cpp
123

From the test I see that FT marker is required, but COV marker is optional. In the original code, LastSeenStartMarker also serves as a flag to mark if the FT marker is presented (by setting it to kInvalidStartMarker). However, because we want to keep LastSeenStartMarker's value to check with COV marker, so I add the HaveFtMarker as a flag to see if the FT marker is presented or not.

yingcong-wu marked an inline comment as done.
  • set init value of HaveFtMarker to ture, for it's ok to not have any STARTED
vitalybuka added inline comments.Mar 21 2023, 11:20 AM
compiler-rt/lib/fuzzer/FuzzerMerge.cpp
123–126

I believe your code is equivalent to

if (!HaveFtMarker && LastSeenStartMarker != kInvalidStartMarker)
  LastFailure = Files[LastSeenStartMarker].Name;

But as I see, the only way to have HaveFtMarker == false is to go through (Marker == "STARTED") so LastSeenStartMarker will be set.
So

LastFailure = Files[LastSeenStartMarker].Name;

will never happen

Would you like to extract HaveFtMarker change into a separate patch, with own test?

yingcong-wu added inline comments.Mar 21 2023, 10:25 PM
compiler-rt/lib/fuzzer/FuzzerMerge.cpp
123–126

I don't see why

LastFailure = Files[LastSeenStartMarker].Name;

will never happen.

When going through (Marker == "STARTED"), HaveFtMarker is set to false and LastSeenStartMarker will have a meaningful value, assuming without going through (Marker == "FT"), then (!HaveFtMarker && LastSeenStartMarker != kInvalidStartMarker) is true and LastFailure = Files[LastSeenStartMarker].Name; will happen.

But I see that the condition could be simplified as you suggested.

Also, I don't think it's a good idea to move HaveFtMarker change to another patch because without HaveFtMarker, this patch will break some LastFailure assertions in fuzzer unittest.

yingcong-wu added inline comments.Mar 21 2023, 10:30 PM
compiler-rt/lib/fuzzer/FuzzerMerge.cpp
123–126

Also, it is difficult to write a test for HaveFtMarker, bacause:

  1. it does not introduce new behavior
  2. merge control with FT maker is ok, so it cannot be test with lit
  3. there are already unittest to test for LastFailure with merge control file which have STARTED but no FT

simplify the LastFailure condition

vitalybuka accepted this revision.Mar 22 2023, 9:49 PM
vitalybuka added inline comments.
compiler-rt/lib/fuzzer/FuzzerMerge.cpp
123–126

I don't see why

LastFailure = Files[LastSeenStartMarker].Name;

will never happen.

Thanks, you are correct.

When going through (Marker == "STARTED"), HaveFtMarker is set to false and LastSeenStartMarker will have a meaningful value, assuming without going through (Marker == "FT"), then (!HaveFtMarker && LastSeenStartMarker != kInvalidStartMarker) is true and LastFailure = Files[LastSeenStartMarker].Name; will happen.

But I see that the condition could be simplified as you suggested.

Also, I don't think it's a good idea to move HaveFtMarker change to another patch because without HaveFtMarker, this patch will break some LastFailure assertions in fuzzer unittest.

If this fixes some assertions then we can count that as a test coverage.

This revision is now accepted and ready to land.Mar 22 2023, 9:49 PM

Thank you. I will remember to mention if something is added to fix testes.

This revision was automatically updated to reflect the committed changes.