Skip to content

Commit

Permalink
Cisco IOS: do not crash on malformed pool (#6568)
Browse files Browse the repository at this point in the history
  • Loading branch information
progwriter committed Jan 15, 2021
1 parent 8322769 commit f31dab4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6128,6 +6128,10 @@ public void exitIpn_pool_prefix(Ipn_pool_prefixContext ctx) {
String name = _currentIosNatPoolName;
Ip first = toIp(ctx.first);
Ip last = toIp(ctx.last);
if (first.compareTo(last) > 0) {
warn(ctx, String.format("Skipping malformed NAT pool %s. First IP > End Ip", name));
return;
}
if (ctx.mask != null) {
Prefix subnet = IpWildcard.ipWithWildcardMask(first, toIp(ctx.mask).inverted()).toPrefix();
createNatPool(name, first, last, subnet, ctx);
Expand All @@ -6145,6 +6149,10 @@ public void exitIpn_pool_range(Ipn_pool_rangeContext ctx) {
String name = _currentIosNatPoolName;
Ip first = toIp(ctx.first);
Ip last = toIp(ctx.last);
if (first.compareTo(last) > 0) {
warn(ctx, String.format("Skipping malformed NAT pool %s. First IP > End Ip", name));
return;
}
if (ctx.prefix_length != null) {
Prefix subnet = Prefix.create(first, Integer.parseInt(ctx.prefix_length.getText()));
createNatPool(name, first, last, subnet, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7361,4 +7361,11 @@ public void testIosVrfLeakingRoutes() throws IOException {
hasNextHop(NextHopVrf.of("SRC_VRF"))))));
assertThat(ribs.get("DST_IMPOSSIBLE").getRoutes(), empty());
}

@Test
public void testNatMalformedNatPool() throws IOException {
String hostname = "ios-nat-malformed-pool";
// Do not crash
parseConfig(hostname);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
hostname ios-nat-malformed-pool

interface Ethernet1
ip nat outside
ip address 3.3.3.3 255.255.255.248

ip access-list standard LIST
permit 1.1.1.1 0.0.0.255
! Note the pool is not a valid range
ip nat pool SNOOKER 10.1.1.10 10.1.1.5 netmask 255.255.255.0
ip nat outside source list LIST pool SNOOKER

0 comments on commit f31dab4

Please sign in to comment.