This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix strcmp fuzz test to use one input.
ClosedPublic

Authored by cgyurgyik on Jun 23 2020, 6:45 PM.

Details

Summary

[libc] Since only one input is given, it is necessary to split the string into two containers so that they can be compared for the purposes of this fuzz test. This is done in the following manner:

  1. Take the value of the first byte; this is size1. (Credits to @PaulkaToast for this idea).
  2. size2 is the value of size - size1.
  3. Copy the characters to new containers, data1 and data2 with corresponding sizes.
  4. Add a null terminator to the first container, and verify the second container has a null terminator.
  5. Verify output of strcmp.

A simpler alternative considered was simply splitting the input data into two, but this means the two strings are always within +- 1 character of each other. This above implementation avoids this.

ninja check-libc was run; no issues.

Diff Detail

Event Timeline

cgyurgyik created this revision.Jun 23 2020, 6:45 PM
cgyurgyik updated this revision to Diff 272887.Jun 23 2020, 6:53 PM

Fix example formatting in comment.

cgyurgyik updated this revision to Diff 272894.Jun 23 2020, 7:24 PM

[libc] Check that new operator[] succeeds.

cgyurgyik updated this revision to Diff 272999.Jun 24 2020, 5:37 AM

Add corresponding deletes.

cgyurgyik updated this revision to Diff 273852.Jun 26 2020, 4:16 PM

[libc] Clean up strcmp fuzz test.

cgyurgyik updated this revision to Diff 273856.Jun 26 2020, 4:23 PM
PaulkaToast accepted this revision.Jun 26 2020, 5:20 PM

Minor nit, looks good otherwise. (:
If you haven't run git clang-format HEAD~1 before you land the patch.

libc/fuzzing/string/strcmp_fuzz.cpp
79

nit: Add a newline.

This revision is now accepted and ready to land.Jun 26 2020, 5:20 PM
cgyurgyik marked an inline comment as done.Jun 28 2020, 10:31 AM

Minor nit, looks good otherwise. (:
If you haven't run git clang-format HEAD~1 before you land the patch.

Weird, I've been running clang-format religiously. I tested it, and it doesn't add a newline at the end.

PaulkaToast accepted this revision.Jun 28 2020, 11:06 AM
cgyurgyik closed this revision.Jun 28 2020, 11:07 AM