From b16033df03db7a6c3e3b3636c9eac4dad8e49f9d Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Sun, 22 Oct 2023 17:01:51 +0200 Subject: Fix fuzz projects (#10416) --- fuzz/Emby.Server.Implementations.Fuzz/Program.cs | 9 ++++++ fuzz/Emby.Server.Implementations.Fuzz/fuzz.sh | 2 +- fuzz/Jellyfin.Api.Fuzz/Jellyfin.Api.Fuzz.csproj | 22 +++++++++++++++ fuzz/Jellyfin.Api.Fuzz/Program.cs | 33 ++++++++++++++++++++++ .../Testcases/UrlDecodeQueryFeature/test1.txt | 1 + fuzz/Jellyfin.Api.Fuzz/fuzz.sh | 11 ++++++++ .../Jellyfin.Server.Fuzz.csproj | 22 --------------- fuzz/Jellyfin.Server.Fuzz/Program.cs | 33 ---------------------- .../Testcases/UrlDecodeQueryFeature/test1.txt | 1 - fuzz/Jellyfin.Server.Fuzz/fuzz.sh | 11 -------- fuzz/README.md | 20 +++++++++++++ 11 files changed, 97 insertions(+), 68 deletions(-) create mode 100644 fuzz/Jellyfin.Api.Fuzz/Jellyfin.Api.Fuzz.csproj create mode 100644 fuzz/Jellyfin.Api.Fuzz/Program.cs create mode 100644 fuzz/Jellyfin.Api.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt create mode 100755 fuzz/Jellyfin.Api.Fuzz/fuzz.sh delete mode 100644 fuzz/Jellyfin.Server.Fuzz/Jellyfin.Server.Fuzz.csproj delete mode 100644 fuzz/Jellyfin.Server.Fuzz/Program.cs delete mode 100644 fuzz/Jellyfin.Server.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt delete mode 100755 fuzz/Jellyfin.Server.Fuzz/fuzz.sh create mode 100644 fuzz/README.md (limited to 'fuzz') diff --git a/fuzz/Emby.Server.Implementations.Fuzz/Program.cs b/fuzz/Emby.Server.Implementations.Fuzz/Program.cs index 03b296494..1571b5ab0 100644 --- a/fuzz/Emby.Server.Implementations.Fuzz/Program.cs +++ b/fuzz/Emby.Server.Implementations.Fuzz/Program.cs @@ -6,6 +6,7 @@ using Emby.Server.Implementations.Library; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Entities; +using Microsoft.Extensions.Configuration; using Moq; using SharpFuzz; @@ -54,8 +55,16 @@ namespace Emby.Server.Implementations.Fuzz appHost.Setup(x => x.ReverseVirtualPath(It.IsAny())) .Returns((string x) => x.Replace(MetaDataPath, VirtualMetaDataPath, StringComparison.Ordinal)); + var configSection = new Mock(); + configSection.SetupGet(x => x[It.Is(s => s == MediaBrowser.Controller.Extensions.ConfigurationExtensions.SqliteCacheSizeKey)]) + .Returns("0"); + var config = new Mock(); + config.Setup(x => x.GetSection(It.Is(s => s == MediaBrowser.Controller.Extensions.ConfigurationExtensions.SqliteCacheSizeKey))) + .Returns(configSection.Object); + IFixture fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); fixture.Inject(appHost); + fixture.Inject(config); return fixture.Create(); } } diff --git a/fuzz/Emby.Server.Implementations.Fuzz/fuzz.sh b/fuzz/Emby.Server.Implementations.Fuzz/fuzz.sh index 37e6bdb76..aa2a34cdd 100755 --- a/fuzz/Emby.Server.Implementations.Fuzz/fuzz.sh +++ b/fuzz/Emby.Server.Implementations.Fuzz/fuzz.sh @@ -8,4 +8,4 @@ cp bin/Emby.Server.Implementations.dll . dotnet build mkdir -p Findings -AFL_SKIP_BIN_CHECK=1 afl-fuzz -i "Testcases/$1" -o "Findings/$1" -t 5000 -m 10240 dotnet bin/Debug/net6.0/Emby.Server.Implementations.Fuzz.dll "$1" +AFL_SKIP_BIN_CHECK=1 afl-fuzz -i "Testcases/$1" -o "Findings/$1" -t 5000 ./bin/Debug/net7.0/Emby.Server.Implementations.Fuzz "$1" diff --git a/fuzz/Jellyfin.Api.Fuzz/Jellyfin.Api.Fuzz.csproj b/fuzz/Jellyfin.Api.Fuzz/Jellyfin.Api.Fuzz.csproj new file mode 100644 index 000000000..da46e63a5 --- /dev/null +++ b/fuzz/Jellyfin.Api.Fuzz/Jellyfin.Api.Fuzz.csproj @@ -0,0 +1,22 @@ + + + + Exe + net7.0 + + + + + Jellyfin.Api.dll + + + + + + + + + + + + diff --git a/fuzz/Jellyfin.Api.Fuzz/Program.cs b/fuzz/Jellyfin.Api.Fuzz/Program.cs new file mode 100644 index 000000000..6713322ac --- /dev/null +++ b/fuzz/Jellyfin.Api.Fuzz/Program.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using Jellyfin.Api.Middleware; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.Extensions.Primitives; +using SharpFuzz; + +namespace Jellyfin.Api.Fuzz +{ + public static class Program + { + public static void Main(string[] args) + { + switch (args[0]) + { + case "UrlDecodeQueryFeature": Run(UrlDecodeQueryFeature); return; + default: throw new ArgumentException($"Unknown fuzzing function: {args[0]}"); + } + } + + private static void Run(Action action) => Fuzzer.OutOfProcess.Run(action); + + private static void UrlDecodeQueryFeature(string data) + { + var dict = new Dictionary + { + { data, StringValues.Empty } + }; + _ = new UrlDecodeQueryFeature(new QueryFeature(new QueryCollection(dict))); + } + } +} diff --git a/fuzz/Jellyfin.Api.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt b/fuzz/Jellyfin.Api.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt new file mode 100644 index 000000000..73f356b93 --- /dev/null +++ b/fuzz/Jellyfin.Api.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt @@ -0,0 +1 @@ +a%3D1%26b%3D2%26c%3D3 diff --git a/fuzz/Jellyfin.Api.Fuzz/fuzz.sh b/fuzz/Jellyfin.Api.Fuzz/fuzz.sh new file mode 100755 index 000000000..edf965562 --- /dev/null +++ b/fuzz/Jellyfin.Api.Fuzz/fuzz.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +dotnet build -c Release ../../Jellyfin.Api/Jellyfin.Api.csproj --output bin +sharpfuzz bin/Jellyfin.Api.dll +cp bin/Jellyfin.Api.dll . + +dotnet build +mkdir -p Findings +AFL_SKIP_BIN_CHECK=1 afl-fuzz -i "Testcases/$1" -o "Findings/$1" -t 5000 ./bin/Debug/net7.0/Jellyfin.Api.Fuzz "$1" diff --git a/fuzz/Jellyfin.Server.Fuzz/Jellyfin.Server.Fuzz.csproj b/fuzz/Jellyfin.Server.Fuzz/Jellyfin.Server.Fuzz.csproj deleted file mode 100644 index 20bc4c724..000000000 --- a/fuzz/Jellyfin.Server.Fuzz/Jellyfin.Server.Fuzz.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - Exe - net7.0 - - - - - jellyfin.dll - - - - - - - - - - - - diff --git a/fuzz/Jellyfin.Server.Fuzz/Program.cs b/fuzz/Jellyfin.Server.Fuzz/Program.cs deleted file mode 100644 index e47286c13..000000000 --- a/fuzz/Jellyfin.Server.Fuzz/Program.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using Jellyfin.Server.Middleware; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.Extensions.Primitives; -using SharpFuzz; - -namespace Emby.Server.Implementations.Fuzz -{ - public static class Program - { - public static void Main(string[] args) - { - switch (args[0]) - { - case "UrlDecodeQueryFeature": Run(UrlDecodeQueryFeature); return; - default: throw new ArgumentException($"Unknown fuzzing function: {args[0]}"); - } - } - - private static void Run(Action action) => Fuzzer.OutOfProcess.Run(action); - - private static void UrlDecodeQueryFeature(string data) - { - var dict = new Dictionary - { - { data, StringValues.Empty } - }; - _ = new UrlDecodeQueryFeature(new QueryFeature(new QueryCollection(dict))); - } - } -} diff --git a/fuzz/Jellyfin.Server.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt b/fuzz/Jellyfin.Server.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt deleted file mode 100644 index 73f356b93..000000000 --- a/fuzz/Jellyfin.Server.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt +++ /dev/null @@ -1 +0,0 @@ -a%3D1%26b%3D2%26c%3D3 diff --git a/fuzz/Jellyfin.Server.Fuzz/fuzz.sh b/fuzz/Jellyfin.Server.Fuzz/fuzz.sh deleted file mode 100755 index 303eb2135..000000000 --- a/fuzz/Jellyfin.Server.Fuzz/fuzz.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -set -e - -dotnet build -c Release ../../Jellyfin.Server/Jellyfin.Server.csproj --output bin -sharpfuzz bin/jellyfin.dll -cp bin/jellyfin.dll . - -dotnet build -mkdir -p Findings -AFL_SKIP_BIN_CHECK=1 afl-fuzz -i "Testcases/$1" -o "Findings/$1" -t 5000 -m 10240 dotnet bin/Debug/net6.0/Jellyfin.Server.Fuzz.dll "$1" diff --git a/fuzz/README.md b/fuzz/README.md new file mode 100644 index 000000000..25ba7d05c --- /dev/null +++ b/fuzz/README.md @@ -0,0 +1,20 @@ +# Jellyfin fuzzing + +## Setup + +Install AFL++ +```sh +git clone https://github.com/AFLplusplus/AFLplusplus +cd AFLplusplus +make all +sudo make install +``` + +Install SharpFuzz.CommandLine global .NET tool +```sh +dotnet tool install --global SharpFuzz.CommandLine +``` + +## Running +Run the `fuzz.sh` in the directory corresponding to the project you want to fuzz. +The script takes a parameter of which fuzz case you want to run. -- cgit v1.2.3