Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/DevelopmentDPC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ name: Development DPC

on:
push:
branches: [ "Development" ]
branches-ignore:
- main
pull_request:
branches: [ "Development" ]
branches-ignore:
- main

jobs:
build:
Expand Down
20 changes: 13 additions & 7 deletions DPCLibrary/Utils/Validate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static bool IPv6(string address)
{
return false; //reject simple IPv6 Zero
}

//Find and reject other ways of making IPv6 Zero
Match zeroResult = Regex.Match(address, "^s*(((0{1,4}:){7}(0{1,4}|:))|((0{1,4}:){6}|(:))|((0{1,4}:){5}(((:0]{1,4}){1,2})|:))|((0{1,4}:){4}(((:0{1,4}){1,3})|((:0{1,4})?:)|:))|((0{1,4}:){3}(((:0{1,4}){1,4})|((:0{1,4}){0,2}:)|:))|((0{1,4}:){2}(((:0{1,4}){1,5})|((:0{1,4}){0,3}:)|:))|((0{1,4}:){1}(((:0{1,4}){1,6})|((:0{1,4}){0,4}:)|:))|(:(((:0{1,4}){1,7})|((:0{1,4}){0,5}:)|:)))(%.+)?s*");
if (zeroResult.Value == address)
Expand Down Expand Up @@ -190,15 +190,16 @@ public static bool IPv4CIDR(string address)
return false;
}

if (!IPv4(SplitCIDR[0]))
string AddressVal = SplitCIDR[0];
if (!int.TryParse(SplitCIDR[1], out int CIDRVal))
{
//Front part isn't a valid address
//Unable to turn second part into int
return false;
}

if (!int.TryParse(SplitCIDR[1], out int CIDRVal))
if (!(AddressVal == "0.0.0.0" || IPv4(AddressVal)))
{
//Unable to turn second part into int
//Front part isn't 0.0.0.0 or a valid address
return false;
}

Expand All @@ -207,7 +208,12 @@ public static bool IPv4CIDR(string address)
return false;
}

if (CIDRVal <= 0)
if (CIDRVal < 0)
{
return false;
}

if (CIDRVal == 0 && AddressVal != "0.0.0.0")
{
return false;
}
Expand Down Expand Up @@ -461,4 +467,4 @@ public static bool PackageId(string id)
}
}
}
}
}
16 changes: 8 additions & 8 deletions DPCLibraryTests/ValidateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class ValidateTests
[DataRow("1.1.1.1/-1")]
[DataRow("1.1.1.1/33")]
[DataRow("1.1.1.1/bob")]
[DataRow("2001:0db9::1/64")]
[DataRow("2001:0db9::1")]
[DataRow("192.168..1/32")]
[DataRow("192.168.1.1/0")]
[DataRow("0.0.0.0")]
public void InvalidIpv4ORCIDR(string IPv4Address)
{
bool result = Validate.IPv4OrCIDR(IPv4Address);
Expand All @@ -50,6 +50,8 @@ public void InvalidIpv4ORCIDR(string IPv4Address)
[DataRow("192.168.0.0/16")]
[DataRow("192.168.1.1/32")]
[DataRow("20.1.2.3/32")]
[DataRow("0.0.0.0/1")]
[DataRow("0.0.0.0/0")]
public void ValidIpv4ORCIDR(string IPv4Address)
{
bool result = Validate.IPv4OrCIDR(IPv4Address);
Expand Down Expand Up @@ -150,13 +152,7 @@ public void InvalidIpv6CIDR(string IPv6Address)
[DataRow("255.255.255.255")]
[DataRow("20.1.2.3")]
[DataRow("0.0.0.0")]
[DataRow("10.0.0.0")]
[DataRow("172.16.35.3")]
[DataRow("192.168.5.4")]
[DataRow("255.255.255.255")]
[DataRow("20.1.2.3")]
[DataRow("172.16.0.0/12")]
[DataRow("10.32.99.0/24")]
[DataRow("192.168.0.0/16")]
[DataRow("192.168.1.1/32")]
[DataRow("20.1.2.3/32")]
Expand Down Expand Up @@ -203,6 +199,8 @@ public void ValidIpv6ORCIDR(string IPv4Address)
[DataRow("192.168.0.0/16")]
[DataRow("192.168.1.1/32")]
[DataRow("20.1.2.3/32")]
[DataRow("0.0.0.0/1")]
[DataRow("0.0.0.0/0")]
public void ValidIpv4ORIpv6ORCIDR(string IPv4Address)
{
bool result = Validate.IPv4OrIPv6OrCIDR(IPv4Address);
Expand Down Expand Up @@ -424,6 +422,8 @@ public void InvalidIpv4CIDR(string IPv4Address)
[DataRow("192.168.0.0/16")]
[DataRow("192.168.1.1/32")]
[DataRow("20.1.2.3/32")]
[DataRow("0.0.0.0/1")]
[DataRow("0.0.0.0/0")]
public void ValidIpv4CIDR(string IPv4Address)
{
bool result = Validate.IPv4CIDR(IPv4Address);
Expand Down