summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/tests/libntp/a_md5encrypt.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2015-10-22 19:42:57 +0000
committerglebius <glebius@FreeBSD.org>2015-10-22 19:42:57 +0000
commit9163b6ba3bf49312e356f13c0a8208d05a79e484 (patch)
treec69f4aae895073471547d394a727baaaa68d758b /contrib/ntp/tests/libntp/a_md5encrypt.c
parentbb011941f0bd9e2ce1ade58a6f1f25eeb2141c9d (diff)
parentaae1e7d66cee27b1a209ea5b8ca21ed12e129103 (diff)
downloadFreeBSD-src-9163b6ba3bf49312e356f13c0a8208d05a79e484.zip
FreeBSD-src-9163b6ba3bf49312e356f13c0a8208d05a79e484.tar.gz
MFV ntp-4.2.8p4 (r289715)
Security: VuXML: c4a18a12-77fc-11e5-a687-206a8a720317 Security: CVE-2015-7871 Security: CVE-2015-7855 Security: CVE-2015-7854 Security: CVE-2015-7853 Security: CVE-2015-7852 Security: CVE-2015-7851 Security: CVE-2015-7850 Security: CVE-2015-7849 Security: CVE-2015-7848 Security: CVE-2015-7701 Security: CVE-2015-7703 Security: CVE-2015-7704, CVE-2015-7705 Security: CVE-2015-7691, CVE-2015-7692, CVE-2015-7702 Security: http://support.ntp.org/bin/view/Main/SecurityNotice#October_2015_NTP_Security_Vulner Sponsored by: Nginx, Inc.
Diffstat (limited to 'contrib/ntp/tests/libntp/a_md5encrypt.c')
-rw-r--r--contrib/ntp/tests/libntp/a_md5encrypt.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/contrib/ntp/tests/libntp/a_md5encrypt.c b/contrib/ntp/tests/libntp/a_md5encrypt.c
index 1738200..f46376e 100644
--- a/contrib/ntp/tests/libntp/a_md5encrypt.c
+++ b/contrib/ntp/tests/libntp/a_md5encrypt.c
@@ -12,14 +12,6 @@
u_long current_time = 4;
-void setUp(void)
-{
-}
-
-void tearDown(void)
-{
-}
-
/*
* Example packet with MD5 hash calculated manually.
*/
@@ -27,37 +19,51 @@ const int keytype = KEY_TYPE_MD5;
const char *key = "abcdefgh";
const u_short keyLength = 8;
const char *packet = "ijklmnopqrstuvwx";
-#define packetLength 16 //const int packetLength = 16;
-#define keyIdLength 4 //const int keyIdLength = 4;
-#define digestLength 16 //const int digestLength = 16;
+#define packetLength 16
+#define keyIdLength 4
+#define digestLength 16
const int totalLength = packetLength + keyIdLength + digestLength;
const char *expectedPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x53";
-void test_Encrypt() {
- char *packetPtr = malloc(totalLength*sizeof(*packetPtr)); //new char[totalLength];
- memset(packetPtr+packetLength, 0, keyIdLength);
+void test_Encrypt(void);
+void test_DecryptValid(void);
+void test_DecryptInvalid(void);
+void test_IPv4AddressToRefId(void);
+void test_IPv6AddressToRefId(void);
+
+
+void
+test_Encrypt(void) {
+ char *packetPtr;
+ int length;
+
+ packetPtr = emalloc(totalLength * sizeof(*packetPtr));
+
+ memset(packetPtr + packetLength, 0, keyIdLength);
memcpy(packetPtr, packet, packetLength);
cache_secretsize = keyLength;
- int length = MD5authencrypt(keytype, (u_char*)key, (u_int32*)packetPtr, packetLength);
+ length = MD5authencrypt(keytype, (u_char*)key, (u_int32*)packetPtr, packetLength);
TEST_ASSERT_TRUE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)packetPtr, packetLength, length));
TEST_ASSERT_EQUAL(20, length);
- TEST_ASSERT_TRUE(memcmp(expectedPacket, packetPtr, totalLength) == 0);
+ TEST_ASSERT_EQUAL_MEMORY(expectedPacket, packetPtr, totalLength);
- free(packetPtr); //delete[] packetPtr;
+ free(packetPtr);
}
-void test_DecryptValid() {
+void
+test_DecryptValid(void) {
cache_secretsize = keyLength;
TEST_ASSERT_TRUE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)expectedPacket, packetLength, 20));
}
-void test_DecryptInvalid() {
+void
+test_DecryptInvalid(void) {
cache_secretsize = keyLength;
const char *invalidPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x54";
@@ -65,18 +71,22 @@ void test_DecryptInvalid() {
TEST_ASSERT_FALSE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)invalidPacket, packetLength, 20));
}
-void test_IPv4AddressToRefId() {
+void
+test_IPv4AddressToRefId(void) {
sockaddr_u addr;
addr.sa4.sin_family = AF_INET;
+ u_int32 address;
+
addr.sa4.sin_port = htons(80);
- u_int32 address = inet_addr("192.0.2.1");
+ address = inet_addr("192.0.2.1");
addr.sa4.sin_addr.s_addr = address;
TEST_ASSERT_EQUAL(address, addr2refid(&addr));
}
-void test_IPv6AddressToRefId() {
+void
+test_IPv6AddressToRefId(void) {
const struct in6_addr address = {
0x20, 0x01, 0x0d, 0xb8,
0x85, 0xa3, 0x08, 0xd3,
OpenPOWER on IntegriCloud