Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cisco IOS: do not crash on malformed pool #6568

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -7291,4 +7291,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