| 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 |
#include <pjlib-util/dns.h> |
| 24 |
#include <pjlib-util/resolver.h> |
| 25 |
|
| 26 |
#define POOL_SIZE 4000 |
| 27 |
|
| 28 |
|
| 29 |
static pj_caching_pool caching_pool; |
| 30 |
static pj_pool_factory *mem; |
| 31 |
|
| 32 |
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
| 33 |
{ |
| 34 |
static int initialized = 0; |
| 35 |
pj_pool_t *pool; |
| 36 |
pj_status_t status; |
| 37 |
pj_dns_parsed_packet *dns; |
| 38 |
|
| 39 |
|
| 40 |
if (!initialized) { |
| 41 |
pj_init(); |
| 42 |
pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); |
| 43 |
pj_log_set_level(0); |
| 44 |
mem = &caching_pool.factory; |
| 45 |
initialized = 1; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
if (Size < 12) |
| 50 |
return 0; |
| 51 |
|
| 52 |
|
| 53 |
pool = pj_pool_create(mem, "dns", POOL_SIZE, POOL_SIZE, NULL); |
| 54 |
if (!pool) |
| 55 |
return 0; |
| 56 |
|
| 57 |
|
| 58 |
status = pj_dns_parse_packet(pool, Data, (unsigned)Size, &dns); |
| 59 |
|
| 60 |
if (status == PJ_SUCCESS && dns && dns->hdr.anscount > 0) { |
| 61 |
|
| 62 |
pj_dns_a_record a_rec; |
| 63 |
pj_dns_parse_a_response(dns, &a_rec); |
| 64 |
|
| 65 |
|
| 66 |
pj_dns_addr_record addr_rec; |
| 67 |
pj_dns_parse_addr_response(dns, &addr_rec); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
pj_pool_release(pool); |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |