| 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.h> |
| 24 |
|
| 25 |
#define kMinInputLength 10 |
| 26 |
#define kMaxInputLength 5120 |
| 27 |
|
| 28 |
pj_pool_factory *mem; |
| 29 |
|
| 30 |
int XML_parse(uint8_t *data, size_t Size) { |
| 31 |
|
| 32 |
pj_pool_t *pool; |
| 33 |
pj_xml_node *root; |
| 34 |
|
| 35 |
char *output; |
| 36 |
size_t output_size; |
| 37 |
|
| 38 |
pool = pj_pool_create(mem, "xml", 4096, 1024, NULL); |
| 39 |
root = pj_xml_parse(pool, (char *)data, Size); |
| 40 |
if (!root) { |
| 41 |
goto on_error; |
| 42 |
} |
| 43 |
|
| 44 |
output = (char*)pj_pool_zalloc(pool, Size + 512); |
| 45 |
output_size = pj_xml_print(root, output, Size + 512, PJ_TRUE); |
| 46 |
if (output_size < 1) { |
| 47 |
goto on_error; |
| 48 |
} |
| 49 |
|
| 50 |
pj_pool_release(pool); |
| 51 |
return 0; |
| 52 |
|
| 53 |
on_error: |
| 54 |
pj_pool_release(pool); |
| 55 |
return 1; |
| 56 |
} |
| 57 |
|
| 58 |
extern int |
| 59 |
LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
| 60 |
{ |
| 61 |
|
| 62 |
if (Size < kMinInputLength || Size > kMaxInputLength) { |
| 63 |
return 1; |
| 64 |
} |
| 65 |
|
| 66 |
int ret = 0; |
| 67 |
uint8_t *data; |
| 68 |
pj_caching_pool caching_pool; |
| 69 |
|
| 70 |
|
| 71 |
data = (uint8_t *)calloc((Size+1), sizeof(uint8_t)); |
| 72 |
memcpy((void *)data, (void *)Data, Size); |
| 73 |
|
| 74 |
|
| 75 |
pj_init(); |
| 76 |
pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0); |
| 77 |
pj_log_set_level(0); |
| 78 |
|
| 79 |
mem = &caching_pool.factory; |
| 80 |
|
| 81 |
|
| 82 |
ret = XML_parse(data, Size); |
| 83 |
|
| 84 |
free(data); |
| 85 |
pj_caching_pool_destroy(&caching_pool); |
| 86 |
|
| 87 |
return ret; |
| 88 |
} |