Skip to content

Commit

Permalink
Project added for fuzz-testing (#74)
Browse files Browse the repository at this point in the history
* 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
gfoidl committed Jul 15, 2019
1 parent abd4c59 commit d624a3c
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,4 @@ _Pvt_Extensions
# Projekte mit Schema nach gfoidl
/source/packages
/NuGet-Packed
/fuzz/instrumented
45 changes: 45 additions & 0 deletions fuzz/gfoidl.Base64.FuzzTests/Program.cs
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 fuzz/gfoidl.Base64.FuzzTests/gfoidl.Base64.FuzzTests.csproj
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>
10 changes: 10 additions & 0 deletions fuzz/init.sh
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
3 changes: 3 additions & 0 deletions fuzz/run.sh
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 $*
1 change: 1 addition & 0 deletions fuzz/testcases/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hallo Welt!
24 changes: 24 additions & 0 deletions gfoidl.Base64.sln
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,50 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{35F8F60F-B
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "gfoidl.Base64.Benchmarks", "perf\gfoidl.Base64.Benchmarks\gfoidl.Base64.Benchmarks.csproj", "{41097931-26CD-4203-B69C-A14CA5FBB69D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fuzz", "fuzz", "{89ADD037-F9FC-4ADE-99B8-D89307057409}"
ProjectSection(SolutionItems) = preProject
fuzz\init.sh = fuzz\init.sh
fuzz\run.sh = fuzz\run.sh
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "gfoidl.Base64.FuzzTests", "fuzz\gfoidl.Base64.FuzzTests\gfoidl.Base64.FuzzTests.csproj", "{DC515055-B8E7-4C25-B4CF-703292C4F975}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testcases", "testcases", "{18096666-86BE-4AEA-AE79-E4528DFFC43C}"
ProjectSection(SolutionItems) = preProject
fuzz\testcases\1.txt = fuzz\testcases\1.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Fuzz|Any CPU = Fuzz|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C85A6AA-23A7-43CC-A744-BD225193369F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C85A6AA-23A7-43CC-A744-BD225193369F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C85A6AA-23A7-43CC-A744-BD225193369F}.Fuzz|Any CPU.ActiveCfg = Debug|Any CPU
{3C85A6AA-23A7-43CC-A744-BD225193369F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C85A6AA-23A7-43CC-A744-BD225193369F}.Release|Any CPU.Build.0 = Release|Any CPU
{3385B383-37A8-4D67-9C84-4B1F32EF15F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3385B383-37A8-4D67-9C84-4B1F32EF15F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3385B383-37A8-4D67-9C84-4B1F32EF15F5}.Fuzz|Any CPU.ActiveCfg = Debug|Any CPU
{3385B383-37A8-4D67-9C84-4B1F32EF15F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3385B383-37A8-4D67-9C84-4B1F32EF15F5}.Release|Any CPU.Build.0 = Release|Any CPU
{C642C23E-7465-4E63-B059-CD67B8C89555}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C642C23E-7465-4E63-B059-CD67B8C89555}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C642C23E-7465-4E63-B059-CD67B8C89555}.Fuzz|Any CPU.ActiveCfg = Debug|Any CPU
{C642C23E-7465-4E63-B059-CD67B8C89555}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C642C23E-7465-4E63-B059-CD67B8C89555}.Release|Any CPU.Build.0 = Release|Any CPU
{41097931-26CD-4203-B69C-A14CA5FBB69D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41097931-26CD-4203-B69C-A14CA5FBB69D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41097931-26CD-4203-B69C-A14CA5FBB69D}.Fuzz|Any CPU.ActiveCfg = Debug|Any CPU
{41097931-26CD-4203-B69C-A14CA5FBB69D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41097931-26CD-4203-B69C-A14CA5FBB69D}.Release|Any CPU.Build.0 = Release|Any CPU
{DC515055-B8E7-4C25-B4CF-703292C4F975}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC515055-B8E7-4C25-B4CF-703292C4F975}.Fuzz|Any CPU.ActiveCfg = Debug|Any CPU
{DC515055-B8E7-4C25-B4CF-703292C4F975}.Fuzz|Any CPU.Build.0 = Debug|Any CPU
{DC515055-B8E7-4C25-B4CF-703292C4F975}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -88,6 +110,8 @@ Global
{BBE8166F-3522-4A1F-87F7-1D88280529C5} = {42D5558B-424A-4A6F-BFD7-F82D344CD4F5}
{C642C23E-7465-4E63-B059-CD67B8C89555} = {A52BCD9C-4216-42E5-AB37-FD5F6C46A9E7}
{41097931-26CD-4203-B69C-A14CA5FBB69D} = {35F8F60F-BAC0-487A-83EB-8588797F3B1F}
{DC515055-B8E7-4C25-B4CF-703292C4F975} = {89ADD037-F9FC-4ADE-99B8-D89307057409}
{18096666-86BE-4AEA-AE79-E4528DFFC43C} = {89ADD037-F9FC-4ADE-99B8-D89307057409}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A902DC31-2F3E-4397-93D1-5004F325B71C}
Expand Down

0 comments on commit d624a3c

Please sign in to comment.