aboutsummaryrefslogtreecommitdiff
path: root/tests/dns.c
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-06-14 20:59:28 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-06-14 20:59:28 +0200
commit0b6026ae2a96c4757688af51d927261536cc2873 (patch)
tree7b125403def39f9d7b87bc19cf0cc4c732e665ad /tests/dns.c
parent64f446220da6f567c818d00a650f92d25391d6e5 (diff)
downloaddns-0b6026ae2a96c4757688af51d927261536cc2873.tar.gz
tests
Diffstat (limited to 'tests/dns.c')
-rw-r--r--tests/dns.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/dns.c b/tests/dns.c
index 9b8a1e9..e75f209 100644
--- a/tests/dns.c
+++ b/tests/dns.c
@@ -38,13 +38,39 @@ START_TEST (dns_qname_fuzz) {
}
ck_assert_float_le( (float)valid_cnt / (float)limit * 100, 10);
-}
+} END_TEST
+
+START_TEST (dns_message_fuzz) {
+ const unsigned long int limit = 1000000;
+ unsigned long int valid_cnt = 0;
+ unsigned long int i;
+
+ struct dns_message msg;
+
+ FILE* urand = fopen ("/dev/urandom", "r");
+ char rand[128];
+
+ if (!urand)
+ ck_abort_msg("Failed to open /dev/urandom");
+
+
+ for (i = 0; i < limit; i++) {
+ if (fread (rand, 128, 1, urand) > 0) {
+ if ( ! dns_parse_packet(rand, 128, &msg) ) {
+ valid_cnt++;
+ }
+ }
+ }
+
+ ck_assert_float_le( (float)valid_cnt / (float)limit * 100, 10);
+} END_TEST
TCase* test_dns(void) {
TCase *tc = tcase_create("DNS");
tcase_add_test(tc, dns_qname);
tcase_add_test(tc, dns_qname_fuzz);
+ tcase_add_test(tc, dns_message_fuzz);
return tc;
}