| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include <stdio.h> |
| 19 |
#include <stdint.h> |
| 20 |
#include <stdlib.h> |
| 21 |
|
| 22 |
#include <pjlib.h> |
| 23 |
|
| 24 |
#include <pjlib-util/dns.h> |
| 25 |
|
| 26 |
#define kMinInputLength 10 |
| 27 |
#define kMaxInputLength 5120 |
| 28 |
|
| 29 |
pj_pool_factory *mem; |
| 30 |
|
| 31 |
int dns_parser(char *data, size_t size) |
| 32 |
{ |
| 33 |
|
| 34 |
int ret = 0; |
| 35 |
pj_pool_t *pool; |
| 36 |
pj_status_t status; |
| 37 |
pj_dns_parsed_packet *dns; |
| 38 |
|
| 39 |
pool = pj_pool_create(mem, "dns_test", 4000, 4000, NULL); |
| 40 |
|
| 41 |
status = pj_dns_parse_packet(pool, data, size, &dns); |
| 42 |
if (status != PJ_SUCCESS) |
| 43 |
ret = 1; |
| 44 |
|
| 45 |
pj_pool_release(pool); |
| 46 |
|
| 47 |
return ret; |
| 48 |
} |
| 49 |
|
| 50 |
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
| 51 |
{ |
| 52 |
int ret = 0; |
| 53 |
char *data; |
| 54 |
pj_caching_pool caching_pool; |
| 55 |
|
| 56 |
if (Size < kMinInputLength || Size > kMaxInputLength) { |
| 57 |
return 1; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
data = (char *)calloc((Size+1), sizeof(char)); |
| 62 |
memcpy((void *)data, (void *)Data, Size); |
| 63 |
|
| 64 |
|
| 65 |
pj_init(); |
| 66 |
pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); |
| 67 |
pj_log_set_level(0); |
| 68 |
|
| 69 |
mem = &caching_pool.factory; |
| 70 |
|
| 71 |
|
| 72 |
ret = dns_parser(data, Size); |
| 73 |
|
| 74 |
free(data); |
| 75 |
pj_caching_pool_destroy(&caching_pool); |
| 76 |
|
| 77 |
return ret; |
| 78 |
} |