12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <pjlib.h>
- #include <pjlib-util.h>
- #define kMinInputLength 10
- #define kMaxInputLength 5120
- pj_pool_factory *mem;
- int Json_parse(uint8_t *data, size_t Size) {
- pj_pool_t *pool;
- pj_json_elem *elem;
- pj_json_err_info err;
- char *output;
- unsigned int output_size;
- pool = pj_pool_create(mem, "json", 1000, 1000, NULL);
- elem = pj_json_parse(pool, (char *)data, (unsigned *)&Size, &err);
- if (!elem) {
- goto on_error;
- }
- output_size = Size * 2;
- output = pj_pool_alloc(pool, output_size);
- if (pj_json_write(elem, output, &output_size)) {
- goto on_error;
- }
- pj_pool_release(pool);
- return 0;
- on_error:
- pj_pool_release(pool);
- return 1;
- }
- extern int
- LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
- {
- if (Size < kMinInputLength || Size > kMaxInputLength) {
- return 1;
- }
- int ret = 0;
- uint8_t *data;
- pj_caching_pool caching_pool;
-
- data = (uint8_t *)calloc((Size+1), sizeof(uint8_t));
- memcpy((void *)data, (void *)Data, Size);
-
- pj_init();
- pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0);
- pj_log_set_level(0);
- mem = &caching_pool.factory;
-
- ret = Json_parse(data, Size);
- free(data);
- pj_caching_pool_destroy(&caching_pool);
- return ret;
- }
|