/src/krb5/fuzzing/Fuzz_chpw.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-int.h" |
18 | | #include "krb5.h" |
19 | | |
20 | 448 | #define kMinInputLength 20 |
21 | 214 | #define kMaxInputLength 100 |
22 | | |
23 | | extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
24 | 224 | {//src/tests/misc/test_chpw_message.c |
25 | | |
26 | 224 | if (Size < kMinInputLength || Size > kMaxInputLength){ |
27 | 40 | return 0; |
28 | 40 | } |
29 | | |
30 | | //Add Null byte |
31 | 184 | uint8_t *DataFx; |
32 | 184 | size_t SizeFx = Size+1; |
33 | 184 | DataFx = (uint8_t *)calloc(SizeFx,sizeof(uint8_t)); |
34 | 184 | memcpy((void *)DataFx,(void *)Data,Size); |
35 | | |
36 | 184 | char *msg; |
37 | 184 | krb5_data DataInput; |
38 | 184 | krb5_context context; |
39 | | |
40 | 184 | krb5_init_context(&context); |
41 | | |
42 | 184 | DataInput = make_data((void *)DataFx, SizeFx); |
43 | | |
44 | 184 | krb5_chpw_message(context, &DataInput, &msg); |
45 | | |
46 | 184 | free(msg); |
47 | 184 | krb5_free_context(context); |
48 | | |
49 | 184 | free(DataFx); |
50 | 184 | return 0; |
51 | 224 | } |