-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project added for fuzz-testing (#74)
* Project added for fuzz-testing https://github.com/Metalnem/sharpfuzz is used for this. * Fuzz-buildconfig otherwise CI will fail, because instrumented isn't checked in * Update fuzz/gfoidl.Base64.FuzzTests/Program.cs
- Loading branch information
Showing
7 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,3 +220,4 @@ _Pvt_Extensions | |
# Projekte mit Schema nach gfoidl | ||
/source/packages | ||
/NuGet-Packed | ||
/fuzz/instrumented |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Text; | ||
using SharpFuzz; | ||
|
||
// see https://github.com/Metalnem/sharpfuzz-samples | ||
|
||
namespace gfoidl.Base64.FuzzTests | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
if (args.Length < 1) | ||
{ | ||
Console.WriteLine("Fuzzing method must be given"); | ||
Environment.Exit(1); | ||
} | ||
|
||
switch (args[0]) | ||
{ | ||
case "Base64_Default_String": Fuzzer.Run(Base64_Default_String); break; | ||
case "Base64_Url_String" : Fuzzer.Run(Base64_Url_String); break; | ||
default: | ||
Console.WriteLine($"Unknown fuzzing function: {args[0]}"); | ||
Environment.Exit(2); | ||
throw null; | ||
} | ||
} | ||
//--------------------------------------------------------------------- | ||
private static void Base64_Default_String(string input) => Base64_String(input, Base64.Default); | ||
private static void Base64_Url_String(string input) => Base64_String(input, Base64.Url); | ||
//--------------------------------------------------------------------- | ||
private static void Base64_String(string input, Base64 encoder) | ||
{ | ||
byte[] inputBytes = Encoding.UTF8.GetBytes(input); | ||
string base64 = encoder.Encode(inputBytes); | ||
byte[] decoded = encoder.Decode(base64); | ||
|
||
if (!inputBytes.AsSpan().SequenceEqual(decoded)) | ||
{ | ||
throw new Exception("Roundtripping failed"); | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
fuzz/gfoidl.Base64.FuzzTests/gfoidl.Base64.FuzzTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="SharpFuzz" Version="1.6.1" /> | ||
<PackageReference Include="Sigil" Version="4.7.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="gfoidl.Base64"> | ||
<HintPath>..\instrumented\gfoidl.Base64.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
echo "See https://github.com/Metalnem/sharpfuzz for setup" | ||
|
||
lib=gfoidl.Base64.dll | ||
|
||
mkdir ./instrumented | ||
cp ../source/gfoidl.Base64/bin/Release/netcoreapp3.0/$lib ./instrumented/$lib | ||
|
||
sharpfuzz ./instrumented/$lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
afl-fuzz -i testcases -o findings -m 10000 dotnet gfoidl.Base64.FuzzTests/bin/Debug/netcoreapp3.0/gfoidl.Base64.FuzzTests.dll $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hallo Welt! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters