summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-07-19 11:30:13 +0200
committerThomas Haller <thaller@redhat.com>2017-07-25 06:44:13 +0200
commit5f995123660cd4d0fe412aa4db0f4f767ec312a2 (patch)
tree5f1ea30f0b8942a61299d20c9a9c8565422e16c4 /src/tests
parent5e5aa39c9737c342367e573b2cc486ca567190a0 (diff)
downloadNetworkManager-5f995123660cd4d0fe412aa4db0f4f767ec312a2.tar.gz
core: prevent invalid routes in NMIP4Config/NMIP6Config
Kernel requires that the host part of a route (based on network/plen) is zero. Routes with non-zero host part don't really exist. In settings (NMIPRoute), we don't enforce that. Hence we must ensure that we don't let such invalid routes into NMIP4Config/NMIP6Config. Also at other places where we obtain routes from untrusted sources, we must sanitize them first. Also add an assertion to catch such bugs.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test-ip4-config.c4
-rw-r--r--src/tests/test-ip6-config.c10
2 files changed, 7 insertions, 7 deletions
diff --git a/src/tests/test-ip4-config.c b/src/tests/test-ip4-config.c
index 80cb1e5c70..d47ff2e643 100644
--- a/src/tests/test-ip4-config.c
+++ b/src/tests/test-ip4-config.c
@@ -75,7 +75,7 @@ test_subtract (void)
const NMPlatformIP4Route *test_route;
const char *expected_addr = "192.168.1.12";
guint32 expected_addr_plen = 24;
- const char *expected_route_dest = "8.7.6.5";
+ const char *expected_route_dest = "8.0.0.0";
guint32 expected_route_plen = 8;
const char *expected_route_next_hop = "192.168.1.1";
guint32 expected_ns1 = nmtst_inet4_from_string ("8.8.8.8");
@@ -232,7 +232,7 @@ test_add_route_with_source (void)
a = nmtst_ip4_config_new (1);
/* Test that a higher priority source is not overwritten */
- route = *nmtst_platform_ip4_route ("1.2.3.4", 24, "1.2.3.1");
+ route = *nmtst_platform_ip4_route ("1.2.3.0", 24, "1.2.3.1");
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip4_config_add_route (a, &route);
diff --git a/src/tests/test-ip6-config.c b/src/tests/test-ip6-config.c
index 5d2283d9da..7079009539 100644
--- a/src/tests/test-ip6-config.c
+++ b/src/tests/test-ip6-config.c
@@ -37,8 +37,8 @@ build_test_config (void)
config = nmtst_ip6_config_new (1);
nm_ip6_config_add_address (config, nmtst_platform_ip6_address ("abcd:1234:4321::cdde", "1:2:3:4::5", 64));
- nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL));
- nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("2001:abba::", 16, "2001:abba::2234", NULL));
+ nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL));
+ nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("2001::", 16, "2001:abba::2234", NULL));
nm_ip6_config_set_gateway (config, nmtst_inet6_from_string ("3001:abba::3234"));
@@ -60,7 +60,7 @@ test_subtract (void)
const NMPlatformIP6Route *test_route;
const char *expected_addr = "1122:3344:5566::7788";
guint32 expected_addr_plen = 96;
- const char *expected_route_dest = "9991:8882:7773::";
+ const char *expected_route_dest = "9991:8800::";
guint32 expected_route_plen = 24;
const char *expected_route_next_hop = "1119:2228:3337:4446::5555";
struct in6_addr expected_ns1;
@@ -139,7 +139,7 @@ test_compare_with_source (void)
nm_ip6_config_add_address (b, &addr);
/* Route */
- route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL);
+ route = *nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL);
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_route (a, &route);
@@ -203,7 +203,7 @@ test_add_route_with_source (void)
a = nmtst_ip6_config_new (1);
/* Test that a higher priority source is not overwritten */
- route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL);
+ route = *nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL);
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_route (a, &route);