< Summary

Information
Class: DotnetFuzzing.Fuzzers.SslStreamClientHelloFuzzer
Assembly: DotnetFuzzing
File(s): D:\runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\SslStreamClientHelloFuzzer.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 26
Coverable lines: 26
Total lines: 48
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
FuzzTarget(...)100%110%

File(s)

D:\runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\SslStreamClientHelloFuzzer.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Buffers;
 5using System.Net.Security;
 6using System.Security.Authentication;
 7
 8namespace DotnetFuzzing.Fuzzers
 9{
 10    internal sealed class SslStreamClientHelloFuzzer : IFuzzer
 11    {
 012        public string[] TargetAssemblies => ["System.Net.Security"];
 13
 014        public string[] TargetCoreLibPrefixes => [];
 15
 16        public void FuzzTarget(ReadOnlySpan<byte> bytes)
 017        {
 018            byte[] buffer = ArrayPool<byte>.Shared.Rent(bytes.Length);
 19            try
 020            {
 021                bytes.CopyTo(buffer);
 022                using MemoryStream ms = new MemoryStream(buffer, 0, bytes.Length);
 023                using SslStream sslStream = new SslStream(ms);
 024                sslStream.AuthenticateAsServerAsync((stream, clientHelloInfo, b, token) =>
 025                {
 026                    // This callback should be called when ClientHello is
 027                    // received, Since we don't parse any other TLS messages,
 028                    // we can terminate the handshake here. Fuzzing the rest of
 029                    // the handshake would fuzz the platform TLS implementation
 030                    // which is not instrumented and is out of scope for this
 031                    // fuzzer.
 032                    throw new MyCustomException();
 033                }, null).GetAwaiter().GetResult();
 034            }
 035            catch (Exception ex) when (ex is AuthenticationException or IOException or MyCustomException)
 036            {
 037            }
 38            finally
 039            {
 040                ArrayPool<byte>.Shared.Return(buffer);
 041            }
 042        }
 43
 44        internal class MyCustomException : Exception
 45        {
 46        }
 47    }
 48}