/src/krb5/fuzzing/Fuzz_json.c
Line | Count | Source |
1 | | /* Copyright 2022 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | #include <stdio.h> |
13 | | #include <stdlib.h> |
14 | | #include <stdint.h> |
15 | | #include <string.h> |
16 | | |
17 | | #include <k5-json.h> |
18 | | |
19 | 7.78k | #define kMinInputLength 10 |
20 | 3.85k | #define kMaxInputLength 1024 |
21 | | |
22 | | extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
23 | 3.89k | {//src/util/support/t_json.c |
24 | | |
25 | 3.89k | if (Size < kMinInputLength || Size > kMaxInputLength){ |
26 | 150 | return 0; |
27 | 150 | } |
28 | | |
29 | | //Add Null byte |
30 | 3.74k | uint8_t *DataFx; |
31 | 3.74k | size_t SizeFx = Size+1; |
32 | 3.74k | DataFx = (uint8_t *)calloc(SizeFx,sizeof(uint8_t)); |
33 | 3.74k | memcpy((void *)DataFx,(void *)Data,Size); |
34 | | |
35 | 3.74k | k5_json_value v; |
36 | 3.74k | k5_json_decode((char *)DataFx, &v); |
37 | 3.74k | k5_json_release(v); |
38 | | |
39 | 3.74k | free(DataFx); |
40 | 3.74k | return 0; |
41 | 3.89k | } |