[libc-commits] [PATCH] D82427: [libc] Fix strcmp fuzz test to use one input.

Chris Gyurgyik via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jun 23 18:54:01 PDT 2020


cgyurgyik created this revision.
cgyurgyik added a project: libc-project.
Herald added subscribers: libc-commits, ecnelises, tschuett, mgorny.
cgyurgyik updated this revision to Diff 272887.
cgyurgyik added a comment.

Fix example formatting in comment.


[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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82427

Files:
  libc/fuzzing/string/strcmp_fuzz.cpp


Index: libc/fuzzing/string/strcmp_fuzz.cpp
===================================================================
--- libc/fuzzing/string/strcmp_fuzz.cpp
+++ libc/fuzzing/string/strcmp_fuzz.cpp
@@ -15,7 +15,7 @@
 
 // The general structure is to take the value of the first byte, set size1 to
 // that value, and add the null terminator. size2 will then contain the rest of
-// the bytes in data. For example: Inputs: data: [2, 6, 4, 8, 0], size: 5 Split:
+// the bytes in data. For example, with inputs ([2, 6, 4, 8, 0], 5):
 //         size1: data[0] = 2
 //         data1: [2, 6] + '\0' = [2, 6, '\0']
 //         size2: size - size1 = 3
@@ -81,4 +81,4 @@
     __builtin_trap();
 
   return 0;
-}
+}
\ No newline at end of file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82427.272887.patch
Type: text/x-patch
Size: 728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200624/60f3fecb/attachment.bin>


More information about the libc-commits mailing list