diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2020-04-04 13:24:21 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2020-04-04 13:24:21 +0200 |
commit | 1cea40f2a843a4db16160b4f620cefd736fc76b5 (patch) | |
tree | e60c4fb3892278e322d258fd0a98c2d0bb600d9a /src | |
parent | c65006ca5107f59e612678891df26d3991823321 (diff) | |
download | dns-1cea40f2a843a4db16160b4f620cefd736fc76b5.tar.gz |
Add packet parser fuzzer test
Diffstat (limited to 'src')
-rw-r--r-- | src/test.c | 38 | ||||
-rw-r--r-- | src/test.h | 4 |
2 files changed, 36 insertions, 6 deletions
@@ -14,13 +14,14 @@ void run_test () //tree_balanced_insert(NULL, NULL, NULL, 15 ); //Normal tests test_tree(); - test_dns_parsing(); - test_dns_parsing_fuzz(); + //test_dns_parsing(); + test_dns_message_fuzz(); + test_dns_qname_fuzz(); } int test_tree () { - printf("\ntest_tree()\n"); + printf("\n-> test_tree()\n======\n\n"); struct tree_node* root = NULL; @@ -42,7 +43,7 @@ int test_tree () int test_dns_parsing () { - printf("test_dns_parsing()\n"); + printf("\n-> test_dns_parsing()\n======\n\n"); char in[128]; char out[128]; @@ -78,7 +79,7 @@ int test_dns_parsing () return 0; } -int test_dns_parsing_fuzz() +int test_dns_qname_fuzz() { printf("\n-> test_parsing_fuzz()\n======\n\n"); FILE* urand = fopen ("/dev/urandom", "r"); @@ -106,4 +107,31 @@ int test_dns_parsing_fuzz() return 0; } + +int test_dns_message_fuzz() +{ + printf("\n-> test_dns_message_fuzz()\n======\n\n"); + FILE* urand = fopen ("/dev/urandom", "r"); + char rand[128]; + + if (!urand) + return 1; + + unsigned long int limit = 10000000; + unsigned long int valid_cnt = 0; + struct dns_message msg; + + for (unsigned long int i = 0; i < limit; i++) { + if (fread (rand, 128, 1, urand) > 0) { + if ( ! dns_parse_packet(rand, 128, &msg) ) { + valid_cnt++; + } + } + } + + float valid_percent = (float)valid_cnt / (float)limit * 100; + printf("# of valid messages in random data: %i / %i = %f%%\n", valid_cnt, limit, valid_percent); + + return 0; +} #endif @@ -24,6 +24,8 @@ int test_tree (); int test_dns_parsing (); -int test_dns_parsing_fuzz(); +int test_dns_qname_fuzz(); + +int test_dns_message_fuzz(); #endif |