diff options
Diffstat (limited to 'tests/dns.c')
-rw-r--r-- | tests/dns.c | 28 |
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; } |