/src/krb5/src/tests/fuzzing/fuzz_marshal_cred.c
Line | Count | Source |
1 | | /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
2 | | /* tests/fuzzing/fuzz_marshal_cred.c */ |
3 | | /* |
4 | | * Copyright (C) 2024 by Arjun. All rights reserved. |
5 | | * |
6 | | * Redistribution and use in source and binary forms, with or without |
7 | | * modification, are permitted provided that the following conditions |
8 | | * are met: |
9 | | * |
10 | | * * Redistributions of source code must retain the above copyright |
11 | | * notice, this list of conditions and the following disclaimer. |
12 | | * |
13 | | * * Redistributions in binary form must reproduce the above copyright |
14 | | * notice, this list of conditions and the following disclaimer in |
15 | | * the documentation and/or other materials provided with the |
16 | | * distribution. |
17 | | * |
18 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
21 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
22 | | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
23 | | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
24 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
25 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
27 | | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
29 | | * OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | | */ |
31 | | |
32 | | /* |
33 | | * Fuzzing harness implementation for k5_unmarshal_cred. |
34 | | */ |
35 | | |
36 | | #include "autoconf.h" |
37 | | #include <cc-int.h> |
38 | | |
39 | 1.17k | #define FIRST_VERSION 1 |
40 | | |
41 | 2.44k | #define kMinInputLength 2 |
42 | 1.21k | #define kMaxInputLength 1024 |
43 | | |
44 | | extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); |
45 | | |
46 | | int |
47 | | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
48 | 1.22k | { |
49 | 1.22k | krb5_error_code ret; |
50 | 1.22k | krb5_creds cred; |
51 | 1.22k | int version; |
52 | 1.22k | struct k5buf buf; |
53 | | |
54 | 1.22k | if (size < kMinInputLength || size > kMaxInputLength) |
55 | 50 | return 0; |
56 | | |
57 | 5.85k | for (version = FIRST_VERSION; version <= 4; version++) { |
58 | 4.68k | ret = k5_unmarshal_cred(data, size, version, &cred); |
59 | 4.68k | if (!ret) { |
60 | 580 | k5_buf_init_dynamic(&buf); |
61 | 580 | k5_marshal_cred(&buf, version, &cred); |
62 | 580 | k5_buf_free(&buf); |
63 | 580 | } |
64 | | |
65 | 4.68k | krb5_free_cred_contents(NULL, &cred); |
66 | 4.68k | } |
67 | | |
68 | 1.17k | return 0; |
69 | 1.22k | } |