]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fixed IP bans preventing non-banned players from connecting to SQLite-backed servers...
authorTGRCDev <tgrc@tgrc.dev>
Sun, 18 Aug 2024 11:53:09 +0000 (04:53 -0700)
committerGitHub <noreply@github.com>
Sun, 18 Aug 2024 11:53:09 +0000 (13:53 +0200)
Fixed IP bans causing server errors with SQLite DB

Content.Server/IP/IPAddressExt.cs
Content.Tests/Server/Utility/IPAddressExtTest.cs

index 6bfa4ef5486d891047c8243cf2c039ba3938a1e0..a61477e01bceb591148dd443597e17f2964c8b04 100644 (file)
@@ -61,6 +61,12 @@ namespace Content.Server.IP
 
         public static bool IsInSubnet(this System.Net.IPAddress address, System.Net.IPAddress maskAddress, int maskLength)
         {
+            if (maskAddress.AddressFamily != address.AddressFamily)
+            {
+                // We got something like an IPV4-Address for an IPv6-Mask. This is not valid.
+                return false;
+            }
+
             if (maskAddress.AddressFamily == AddressFamily.InterNetwork)
             {
                 // Convert the mask address to an unsigned integer.
@@ -89,7 +95,7 @@ namespace Content.Server.IP
 
                 if (maskAddressBits.Length != ipAddressBits.Length)
                 {
-                    throw new ArgumentException("Length of IP Address and Subnet Mask do not match.");
+                    return false;
                 }
 
                 // Compare the prefix bits.
index a57430267b806f947054c1bae7043bbeb0c83d8c..dba8a0e6aae4941850f41b815fa13af583768b3d 100644 (file)
@@ -26,6 +26,7 @@ namespace Content.Tests.Server.Utility
         [TestCase("10.128.240.50/30", "10.128.240.52")]
         [TestCase("10.128.240.50/30", "10.128.239.50")]
         [TestCase("10.128.240.50/30", "10.127.240.51")]
+        [TestCase("10.128.240.50/30", "2001:0DB8:ABCD:0012:0000:0000:0000:0000")]
         public void IpV4SubnetMaskDoesNotMatchInvalidIpAddress(string netMask, string ipAddress)
         {
             var ipAddressObj = IPAddress.Parse(ipAddress);
@@ -51,6 +52,7 @@ namespace Content.Tests.Server.Utility
         [TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0013:0001:0000:0000:0000")]
         [TestCase("2001:db8:abcd:0012::0/64", "2001:0DB8:ABCD:0011:FFFF:FFFF:FFFF:FFF0")]
         [TestCase("2001:db8:abcd:0012::0/128", "2001:0DB8:ABCD:0012:0000:0000:0000:0001")]
+        [TestCase("2001:db8:abcd:0012::0/128", "10.128.239.50")]
         // ReSharper restore StringLiteralTypo
         public void IpV6SubnetMaskDoesNotMatchInvalidIpAddress(string netMask, string ipAddress)
         {