Skip to content

Commit

Permalink
Merge d8c1c3c into cba6b9f
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Oct 17, 2019
2 parents cba6b9f + d8c1c3c commit 67eee41
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 10 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ulimit -n 2048; fi
install:
- dotnet tool install -g dotnet-format --version 4.0.40103 --add-source https://dotnet.myget.org/F/format/api/v3/index.json
- dotnet tool install -g coveralls.net --version 1.0.0
- export PATH="$PATH:$HOME/.dotnet/tools"
- dotnet-format --version
- csmacnz.Coveralls --version
before_script:
- echo "Checking format ..."
- echo "Extracting author information ..."
- export COMMITTER_EMAIL="$(git log -1 $TRAVIS_COMMIT --pretty="%cE")"
- export AUTHOR_NAME="$(git log -1 $TRAVIS_COMMIT --pretty="%aN")"
- echo "Checking format ..."
- dotnet format --check --dry-run -w src/TuringMachine -v diagnostic
- dotnet format --check --dry-run -w src/TuringMachine.Core -v diagnostic
- dotnet format --check --dry-run -w tests/TuringMachine.Core.Tests -v diagnostic
Expand All @@ -28,7 +33,9 @@ script:
- cd tests/TuringMachine.Core.Tests
- dotnet restore
- find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild
- dotnet test -v m /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
- dotnet test -v m /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput='../../coverage.xml' /p:Exclude=\"[coverlet.*]*,[*]Coverlet.Core*\"
after_success:
- echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG)"
- bash <(curl -s https://codecov.io/bash)
- echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG) Author($AUTHOR_NAME) CommitterEmail($COMMITTER_EMAIL)"
# - bash <(curl -s https://codecov.io/bash)
- cd ../../
- csmacnz.Coveralls --opencover -i coverage.xml --repoTokenVariable COVERALLS_REPO_TOKEN --useRelativePaths --commitId $TRAVIS_COMMIT --commitBranch $TRAVIS_BRANCH --jobId $TRAVIS_JOB_ID --commitMessage "$TRAVIS_COMMIT_MESSAGE" --commitAuthor "$AUTHOR_NAME" --commitEmail "$COMMITTER_EMAIL"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<a href="https://travis-ci.org/Red4Sec/TuringMachine" target="_blank">
<img src="https://travis-ci.org/Red4Sec/TuringMachine.svg?branch=master" alt="Current TravisCI build status.">
</a>
<a href="https://codecov.io/gh/Red4Sec/TuringMachine" target="_blank">
<img src="https://codecov.io/github/Red4Sec/TuringMachine/branch/master/graph/badge.svg" alt="Current Coverage Status." />
<a href='https://coveralls.io/github/Red4Sec/TuringMachine?branch=master' target="_blank">
<img src='https://coveralls.io/repos/github/Red4Sec/TuringMachine/badge.svg?branch=master' alt='Coverage Status' />
</a>
<a href="https://github.com/Red4Sec/TuringMachine/blob/master/LICENSE" target="_blank">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License.">
Expand Down
7 changes: 6 additions & 1 deletion src/TuringMachine.Core/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static bool EqualWithNullCheck<T>(this IEquatable<T> a, IEquatable<T> b)
/// <returns>True if are equals</returns>
public static bool SequenceEqualWithNullCheck<T>(this IList<T> a, IList<T> b)
{
if (typeof(T) == typeof(byte[]))
{
return ChunkSequenceEqualWithNullCheck((IList<byte[]>)a, (IList<byte[]>)b);
}

if ((a == null) != (b == null))
{
return false;
Expand All @@ -50,7 +55,7 @@ public static bool SequenceEqualWithNullCheck<T>(this IList<T> a, IList<T> b)
/// <param name="a">A</param>
/// <param name="b">B</param>
/// <returns>True if are equals</returns>
public static bool ChunkSequenceEqualWithNullCheck(this IList<byte[]> chunks1, IList<byte[]> chunks2)
private static bool ChunkSequenceEqualWithNullCheck(this IList<byte[]> chunks1, IList<byte[]> chunks2)
{
if ((chunks1 == null) != (chunks2 == null)) return false;
if (chunks1 == null) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public bool Equals(MutationalChunk obj)
if (obj == null) return false;

return obj.Type == Type
&& obj.Allowed.ChunkSequenceEqualWithNullCheck(Allowed);
&& obj.Allowed.SequenceEqualWithNullCheck(Allowed);
}

/// <summary>
Expand Down
51 changes: 51 additions & 0 deletions tests/TuringMachine.Core.Tests/Extensions/ObjectExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Net;
using TuringMachine.Core.Extensions;

namespace TuringMachine.Core.Tests.Extensions
{
[TestFixture]
public class ObjectExtensionsTest
{
[Test]
public void ClearTest()
{
// IPEndPoint

Assert.IsFalse(ObjectExtensions.EqualWithNullCheck(new IPEndPoint(0, 1), null));
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck(null, new IPEndPoint(0, 1)));
Assert.IsTrue(ObjectExtensions.EqualWithNullCheck(new IPEndPoint(0, 1), new IPEndPoint(0, 1)));
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck(new IPEndPoint(0, 1), new IPEndPoint(0, 2)));

// Byte[]

Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new byte[] { 0x00, 0x01 }, null));
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(null, new byte[] { 0x00, 0x01 }));
Assert.IsTrue(ObjectExtensions.SequenceEqualWithNullCheck(new byte[] { 0x00, 0x01 }, new byte[] { 0x00, 0x01 }));
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new byte[] { 0x00, 0x01 }, new byte[] { 0x00, 0x02 }));

// IList

Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte>(new byte[] { 0x00, 0x01 }), null));
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(null, new List<byte>(new byte[] { 0x00, 0x01 })));
Assert.IsTrue(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte>(new byte[] { 0x00, 0x01 }), new List<byte>(new byte[] { 0x00, 0x01 })));
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte>(new byte[] { 0x00, 0x01 }), new List<byte>(new byte[] { 0x00, 0x02 })));

// IEquatable

Assert.IsFalse(ObjectExtensions.EqualWithNullCheck((IEquatable<Decimal>)new Decimal(1), null));
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck(null, (IEquatable<Decimal>)new Decimal(1)));
Assert.IsTrue(ObjectExtensions.EqualWithNullCheck((IEquatable<Decimal>)new Decimal(1), (IEquatable<Decimal>)new Decimal(1)));
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck((IEquatable<Decimal>)new Decimal(1), (IEquatable<Decimal>)new Decimal(2)));

// IList<byte[]>

Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } }), null));
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(null, new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } })));
Assert.IsTrue(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } }), new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } })));
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } }), new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x02 } })));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public void MutationalEntryPeerByteTest()
entry.Changes.Add(new MutationalChange()
{
Weight = 5,
Description = "Add A",
Append = new MutationalFromTo((byte)'A'),
RemoveLength = new FromToValue<ushort>(1),
AppendIterations = new FromToValue<ushort>(1)
Expand All @@ -348,6 +349,7 @@ public void MutationalEntryPeerByteTest()
{
// Remmove
Weight = 1,
Description = "Remove",
RemoveLength = new FromToValue<ushort>(1),
AppendIterations = new FromToValue<ushort>(1)
});
Expand Down Expand Up @@ -407,13 +409,14 @@ public void MutationalEntryPeerByteTest()

// Max changes 2

entry.Changes.RemoveAt(1);
entry.ValidOffset = new FromToValue<long>(0, long.MaxValue);
entry.MaxChanges = new FromToValue<ushort>(2);

input = new ManualFuzzingInput(new byte[100]);

using (var stream = new FuzzingStream(config, input.GetStream()))
{
stream.CopyTo(new MemoryStream(), 100);
stream.CopyTo(new MemoryStream(), 16);

Assert.AreEqual(2, stream.Log.Length);
Assert.AreEqual(0, stream.Log[0].Offset);
Expand Down
26 changes: 26 additions & 0 deletions tests/TuringMachine.Core.Tests/FuzzingStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ namespace TuringMachine.Core.Tests
[TestFixture]
public class FuzzingStreamTest
{
class Disposable : IDisposable
{
public int IsDisposed = 0;

public void Dispose()
{
IsDisposed++;
}
}

[Test]
public void DisposeTest()
{
var original = new byte[90];
var disposed = new Disposable();

using (var stream = new FuzzingStream(null, original))
{
stream.Variables.Add(0, disposed);

Assert.AreEqual(0, disposed.IsDisposed);
}

Assert.AreEqual(1, disposed.IsDisposed);
}

[Test]
public void CleanTest()
{
Expand Down

0 comments on commit 67eee41

Please sign in to comment.