aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2020-06-24 00:20:45 +0000
committerCy Schubert <cy@FreeBSD.org>2020-06-24 00:20:45 +0000
commit3914721463f70500ecc1f59312b122d8788465cf (patch)
treef253e72838d762e229ca71912a4a928e96cac2bd /tests
parent5171bc9b11192d9ad273db7854787eaa65eb9997 (diff)
downloadsrc-vendor/ntp.tar.gz
src-vendor/ntp.zip
Import ntp-4.2.8p15.vendor/ntp/4.2.8p15vendor/ntp
Security: ntp bug 3661
Notes
Notes: svn path=/vendor/ntp/dist/; revision=362565 svn path=/vendor/ntp/4.2.8p15/; revision=362566; tag=vendor/ntp/4.2.8p15
Diffstat (limited to 'tests')
-rw-r--r--tests/libntp/decodenetnum.c100
-rw-r--r--tests/libntp/netof.c2
-rw-r--r--tests/libntp/recvbuff.c4
-rw-r--r--tests/libntp/run-decodenetnum.c10
-rw-r--r--tests/libntp/sockaddrtest.c13
5 files changed, 113 insertions, 16 deletions
diff --git a/tests/libntp/decodenetnum.c b/tests/libntp/decodenetnum.c
index 85463e868d0b..961ea6d308c9 100644
--- a/tests/libntp/decodenetnum.c
+++ b/tests/libntp/decodenetnum.c
@@ -9,8 +9,11 @@ extern void test_IPv4AddressOnly(void);
extern void test_IPv4AddressWithPort(void);
extern void test_IPv6AddressOnly(void);
extern void test_IPv6AddressWithPort(void);
+extern void test_IPv6AddressWithScope(void);
+extern void test_IPv6AddressWithPortAndScope(void);
extern void test_IllegalAddress(void);
extern void test_IllegalCharInPort(void);
+extern void test_NameBufOverflow(void);
/*
* NOTE: The IPv6 specific tests are reduced to stubs when IPv6 is
@@ -35,6 +38,7 @@ test_IPv4AddressOnly(void)
sockaddr_u actual;
sockaddr_u expected;
+ memset(&expected, 0, sizeof(expected));
expected.sa4.sin_family = AF_INET;
expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
SET_PORT(&expected, NTP_PORT);
@@ -50,6 +54,7 @@ test_IPv4AddressWithPort(void)
sockaddr_u actual;
sockaddr_u expected;
+ memset(&expected, 0, sizeof(expected));
expected.sa4.sin_family = AF_INET;
expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.2");
SET_PORT(&expected, 2000);
@@ -71,21 +76,26 @@ test_IPv6AddressOnly(void)
0x03, 0x70, 0x73, 0x34
};
- const char *str = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
+ const char *str1 = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
+ const char *str2 = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334]";
sockaddr_u actual;
sockaddr_u expected;
+ memset(&expected, 0, sizeof(expected));
expected.sa6.sin6_family = AF_INET6;
expected.sa6.sin6_addr = address;
SET_PORT(&expected, NTP_PORT);
- TEST_ASSERT_TRUE(decodenetnum(str, &actual));
+ TEST_ASSERT_TRUE(decodenetnum(str1, &actual));
+ TEST_ASSERT_TRUE(IsEqual(expected, actual));
+
+ TEST_ASSERT_TRUE(decodenetnum(str2, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
#else
-
+
TEST_IGNORE_MESSAGE("IPV6 disabled in build");
-
+
#endif
}
@@ -106,6 +116,7 @@ test_IPv6AddressWithPort(void)
sockaddr_u actual;
sockaddr_u expected;
+ memset(&expected, 0, sizeof(expected));
expected.sa6.sin6_family = AF_INET6;
expected.sa6.sin6_addr = address;
SET_PORT(&expected, 3000);
@@ -114,12 +125,77 @@ test_IPv6AddressWithPort(void)
TEST_ASSERT_TRUE(IsEqual(expected, actual));
#else
-
+
+ TEST_IGNORE_MESSAGE("IPV6 disabled in build");
+
+#endif
+}
+
+void test_IPv6AddressWithScope(void)
+{
+#if defined(ISC_PLATFORM_HAVEIPV6) && defined(WANT_IPV6)
+
+ const struct in6_addr address = {
+ 0x20, 0x01, 0x0d, 0xb8,
+ 0x85, 0xa3, 0x08, 0xd3,
+ 0x13, 0x19, 0x8a, 0x2e,
+ 0x03, 0x70, 0x73, 0x34
+ };
+
+ const char *str1 = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334%42";
+ const char *str2 = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334%42]";
+ sockaddr_u actual;
+
+ sockaddr_u expected;
+ memset(&expected, 0, sizeof(expected));
+ expected.sa6.sin6_family = AF_INET6;
+ expected.sa6.sin6_addr = address;
+ expected.sa6.sin6_scope_id = 42;
+ SET_PORT(&expected, NTP_PORT);
+
+ TEST_ASSERT_TRUE(decodenetnum(str1, &actual));
+ TEST_ASSERT_TRUE(IsEqual(expected, actual));
+
+ TEST_ASSERT_TRUE(decodenetnum(str2, &actual));
+ TEST_ASSERT_TRUE(IsEqual(expected, actual));
+
+#else
+
TEST_IGNORE_MESSAGE("IPV6 disabled in build");
-
+
#endif
}
+void test_IPv6AddressWithPortAndScope(void)
+{
+#if defined(ISC_PLATFORM_HAVEIPV6) && defined(WANT_IPV6)
+
+ const struct in6_addr address = {
+ 0x20, 0x01, 0x0d, 0xb8,
+ 0x85, 0xa3, 0x08, 0xd3,
+ 0x13, 0x19, 0x8a, 0x2e,
+ 0x03, 0x70, 0x73, 0x34
+ };
+
+ const char *str = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334%42]:3000";
+ sockaddr_u actual;
+
+ sockaddr_u expected;
+ memset(&expected, 0, sizeof(expected));
+ expected.sa6.sin6_family = AF_INET6;
+ expected.sa6.sin6_addr = address;
+ expected.sa6.sin6_scope_id = 42;
+ SET_PORT(&expected, 3000);
+
+ TEST_ASSERT_TRUE(decodenetnum(str, &actual));
+ TEST_ASSERT_TRUE(IsEqual(expected, actual));
+
+#else
+
+ TEST_IGNORE_MESSAGE("IPV6 disabled in build");
+
+#endif
+}
void
test_IllegalAddress(void)
@@ -141,6 +217,7 @@ test_IllegalCharInPort(void)
sockaddr_u actual;
sockaddr_u expected;
+ memset(&expected, 0, sizeof(expected));
expected.sa4.sin_family = AF_INET;
expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
SET_PORT(&expected, NTP_PORT);
@@ -148,3 +225,14 @@ test_IllegalCharInPort(void)
TEST_ASSERT_TRUE(decodenetnum(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
}
+
+void
+test_NameBufOverflow(void)
+{
+ const char *str =
+ "loremipsumloremipsumloremipsumloremipsumloremipsum"
+ "loremipsumloremipsumloremipsumloremipsum";
+
+ sockaddr_u actual;
+ TEST_ASSERT_FALSE(decodenetnum(str, &actual));
+}
diff --git a/tests/libntp/netof.c b/tests/libntp/netof.c
index 59dd7098d2a7..be197cf18b8a 100644
--- a/tests/libntp/netof.c
+++ b/tests/libntp/netof.c
@@ -89,11 +89,13 @@ test_IPv6Address(void)
} } }; // 2001:0db8:85a3:08d3:0000:0000:0000:0000
sockaddr_u input;
+ memset(&input, 0, sizeof(input));
input.sa6.sin6_family = AF_INET6;
input.sa6.sin6_addr = input_address;
SET_PORT(&input, 3000);
sockaddr_u expected;
+ memset(&expected, 0, sizeof(expected));
expected.sa6.sin6_family = AF_INET6;
expected.sa6.sin6_addr = expected_address;
SET_PORT(&expected, 3000);
diff --git a/tests/libntp/recvbuff.c b/tests/libntp/recvbuff.c
index 6c089bb4c33f..90986e0aba95 100644
--- a/tests/libntp/recvbuff.c
+++ b/tests/libntp/recvbuff.c
@@ -29,7 +29,7 @@ test_Initialization(void) {
void
test_GetAndFree(void) {
u_long initial = free_recvbuffs();
- recvbuf_t* buf = get_free_recv_buffer();
+ recvbuf_t* buf = get_free_recv_buffer(TRUE);
TEST_ASSERT_EQUAL_UINT(initial-1, free_recvbuffs());
freerecvbuf(buf);
@@ -40,7 +40,7 @@ test_GetAndFree(void) {
void
test_GetAndFill(void) {
// int initial = free_recvbuffs();
- recvbuf_t* buf = get_free_recv_buffer();
+ recvbuf_t* buf = get_free_recv_buffer(TRUE);
add_full_recv_buffer(buf);
TEST_ASSERT_EQUAL_UINT(1, full_recvbuffs());
diff --git a/tests/libntp/run-decodenetnum.c b/tests/libntp/run-decodenetnum.c
index ef2b3c68eb61..0d306497201a 100644
--- a/tests/libntp/run-decodenetnum.c
+++ b/tests/libntp/run-decodenetnum.c
@@ -33,8 +33,11 @@ extern void test_IPv4AddressOnly(void);
extern void test_IPv4AddressWithPort(void);
extern void test_IPv6AddressOnly(void);
extern void test_IPv6AddressWithPort(void);
+extern void test_IPv6AddressWithScope(void);
+extern void test_IPv6AddressWithPortAndScope(void);
extern void test_IllegalAddress(void);
extern void test_IllegalCharInPort(void);
+extern void test_NameBufOverflow(void);
//=======Suite Setup=====
@@ -67,8 +70,11 @@ int main(int argc, char *argv[])
RUN_TEST(test_IPv4AddressWithPort, 9);
RUN_TEST(test_IPv6AddressOnly, 10);
RUN_TEST(test_IPv6AddressWithPort, 11);
- RUN_TEST(test_IllegalAddress, 12);
- RUN_TEST(test_IllegalCharInPort, 13);
+ RUN_TEST(test_IPv6AddressWithScope, 12);
+ RUN_TEST(test_IPv6AddressWithPortAndScope, 13);
+ RUN_TEST(test_IllegalAddress, 14);
+ RUN_TEST(test_IllegalCharInPort, 15);
+ RUN_TEST(test_NameBufOverflow, 16);
return (UnityEnd());
}
diff --git a/tests/libntp/sockaddrtest.c b/tests/libntp/sockaddrtest.c
index bbf669c78487..5a37fab56fea 100644
--- a/tests/libntp/sockaddrtest.c
+++ b/tests/libntp/sockaddrtest.c
@@ -26,9 +26,9 @@ IsEqual(const sockaddr_u expected, const sockaddr_u actual) {
}
if (actual.sa.sa_family == AF_INET) { // IPv4
- if (expected.sa4.sin_port == actual.sa4.sin_port &&
- memcmp(&expected.sa4.sin_addr, &actual.sa4.sin_addr,
- sizeof( in )) == 0) {
+ if ( expected.sa4.sin_port == actual.sa4.sin_port
+ && memcmp(&expected.sa4.sin_addr, &actual.sa4.sin_addr,
+ sizeof( in )) == 0) {
return TRUE;
} else {
char buf[4][32];
@@ -41,9 +41,10 @@ IsEqual(const sockaddr_u expected, const sockaddr_u actual) {
return FALSE;
}
} else if (actual.sa.sa_family == AF_INET6) { //IPv6
- if (expected.sa6.sin6_port == actual.sa6.sin6_port &&
- memcmp(&expected.sa6.sin6_addr, &actual.sa6.sin6_addr,
- sizeof(in6)) == 0) {
+ if ( expected.sa6.sin6_port == actual.sa6.sin6_port
+ && expected.sa6.sin6_scope_id == actual.sa6.sin6_scope_id
+ && memcmp(&expected.sa6.sin6_addr, &actual.sa6.sin6_addr,
+ sizeof(in6)) == 0) {
return TRUE;
} else {
printf("IPv6 comparision failed");