Skip to content

Commit 36af7d1

Browse files
Gizachew-EshetieGizachew Eshetie
andauthored
Fixed SNAT private ranges IP validation bug (#18857)
* Fixed SNAT private ranges IP validation bug * Updated Changelog * updated session records Co-authored-by: Gizachew Eshetie <[email protected]>
1 parent 3b56c93 commit 36af7d1

File tree

7 files changed

+721
-874
lines changed

7 files changed

+721
-874
lines changed

src/Network/Network.Test/ScenarioTests/AzureFirewallPolicyTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ function Test-AzureFirewallPolicyPrivateRangeCRUD {
14921492
$location = "westus2"
14931493
$vnetName = Get-ResourceName
14941494
$privateRange2 = @("IANAPrivateRanges", "0.0.0.0/0", "66.92.0.0/16")
1495-
$privateRange1 = @("3.3.0.0/24", "98.0.0.0/8")
1495+
$privateRange1 = @("3.3.0.0/24", "98.0.0.0/8","10.227.16.0/20")
14961496
$privateRange2Translated = @("0.0.0.0/0", "66.92.0.0/16", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "100.64.0.0/10")
14971497

14981498
try {

src/Network/Network.Test/ScenarioTests/AzureFirewallTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ function Test-AzureFirewallPrivateRangeCRUD {
13501350
$publicIpName = Get-ResourceName
13511351

13521352
$privateRange1 = @("IANAPrivateRanges", "0.0.0.0/0", "66.92.0.0/16")
1353-
$privateRange2 = @("3.3.0.0/24", "98.0.0.0/8")
1353+
$privateRange2 = @("3.3.0.0/24", "98.0.0.0/8","10.227.16.0/20","10.226.0.0/16")
13541354

13551355
try {
13561356
# Create the resource group

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.AzureFirewallPolicyTests/TestAzureFirewallPolicyPrivateRangeCRUD.json

Lines changed: 235 additions & 235 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.AzureFirewallTests/TestAzureFirewallPrivateRangeCRUD.json

Lines changed: 480 additions & 634 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Fixed bug that causes an overflow due to incorrect SNAT private ranges IP validation.
2223
* Added new cmdlets to create/manage L4(TCP/TLS) objects for ApplicationGateway:
2324
- `Get-AzApplicationGatewayListener`
2425
- `New-AzApplicationGatewayListener`

src/Network/Network/Models/AzureFirewall/PSAzureFirewall.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ private void ValidateMaskedIpAddress(string ipAddress)
452452

453453
// validated that unmasked bits are 0
454454
var splittedIp = split[0].Split('.');
455-
var ip = Int32.Parse(splittedIp[0]) << 24;
456-
ip = ip + Int32.Parse(splittedIp[1]) << 16 + Int32.Parse(splittedIp[2]) << 8 + Int32.Parse(splittedIp[3]);
455+
var ip = Int32.Parse(splittedIp[0]) << 24;
456+
ip += (Int32.Parse(splittedIp[1]) << 16) + (Int32.Parse(splittedIp[2]) << 8) + Int32.Parse(splittedIp[3]);
457457
if (ip << bit != 0)
458458
throw new PSArgumentException(String.Format("\'{0}\' is not a valid private range ip address, bits not covered by subnet mask should be all 0", ipAddress));
459459
}

src/Network/Network/Models/AzureFirewallPolicy/PSAzureFirewallPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void ValidateMaskedIpAddress(string ipAddress)
117117
// validated that unmasked bits are 0
118118
var splittedIp = split[0].Split('.');
119119
var ip = Int32.Parse(splittedIp[0]) << 24;
120-
ip = ip + Int32.Parse(splittedIp[1]) << 16 + Int32.Parse(splittedIp[2]) << 8 + Int32.Parse(splittedIp[3]);
120+
ip += (Int32.Parse(splittedIp[1]) << 16) + (Int32.Parse(splittedIp[2]) << 8) + Int32.Parse(splittedIp[3]);
121121
if (ip << bit != 0)
122122
throw new AzPSArgumentException(String.Format(Resources.InvalidPrivateIPRangeUnmaskedBits, ipAddress), nameof(ipAddress), ErrorKind.UserError);
123123
}

0 commit comments

Comments
 (0)