| 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 |
#include "../../pjlib-util/src/pjlib-util/http_client.c" |
| 25 |
|
| 26 |
#define kMinInputLength 10 |
| 27 |
#define kMaxInputLength 1024 |
| 28 |
|
| 29 |
pj_pool_factory *mem; |
| 30 |
|
| 31 |
int http_parse(uint8_t *data, size_t Size) { |
| 32 |
|
| 33 |
int ret; |
| 34 |
pj_pool_t *pool; |
| 35 |
pj_size_t rem; |
| 36 |
pj_http_resp response; |
| 37 |
|
| 38 |
pool = pj_pool_create(mem, "http", 1000, 1000, NULL); |
| 39 |
|
| 40 |
ret = http_response_parse(pool, &response, data, Size, &rem); |
| 41 |
|
| 42 |
pj_pool_release(pool); |
| 43 |
|
| 44 |
return ret; |
| 45 |
} |
| 46 |
|
| 47 |
extern int |
| 48 |
LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
| 49 |
{ |
| 50 |
|
| 51 |
if (Size < kMinInputLength || Size > kMaxInputLength) { |
| 52 |
return 1; |
| 53 |
} |
| 54 |
|
| 55 |
int ret = 0; |
| 56 |
uint8_t *data; |
| 57 |
pj_caching_pool caching_pool; |
| 58 |
|
| 59 |
|
| 60 |
data = (uint8_t *)calloc((Size+1), sizeof(uint8_t)); |
| 61 |
memcpy((void *)data, (void *)Data, Size); |
| 62 |
|
| 63 |
|
| 64 |
pj_init(); |
| 65 |
pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0); |
| 66 |
pj_log_set_level(0); |
| 67 |
|
| 68 |
mem = &caching_pool.factory; |
| 69 |
|
| 70 |
|
| 71 |
ret = http_parse(data, Size); |
| 72 |
|
| 73 |
free(data); |
| 74 |
pj_caching_pool_destroy(&caching_pool); |
| 75 |
|
| 76 |
return ret; |
| 77 |
} |