Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/tests/fuzzing/fuzz_attrset.c
34879 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/* tests/fuzzing/fuzz_attrset.c - fuzzing harness for kr_attrset functions */
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
#include "autoconf.h"
33
#include <k5-int.h>
34
#include <internal.h>
35
36
#define kMinInputLength 2
37
#define kMaxInputLength 1024
38
39
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
40
41
int
42
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
43
{
44
krb5_error_code ret;
45
krb5_context context;
46
krad_attrset *set;
47
krb5_data data_in;
48
uint8_t buffer[KRAD_PACKET_SIZE_MAX], auth[MD5_DIGEST_SIZE] = { 0 };
49
size_t encode_len;
50
51
if (size < kMinInputLength || size > kMaxInputLength)
52
return 0;
53
54
data_in = make_data((void *)data, size);
55
56
ret = krb5_init_context(&context);
57
if (ret)
58
return 0;
59
60
ret = kr_attrset_decode(context, &data_in, "f", auth, &set);
61
if (!ret)
62
kr_attrset_encode(set, "f", auth, FALSE, buffer, &encode_len);
63
64
krad_attrset_free(set);
65
krb5_free_context(context);
66
67
return 0;
68
}
69
70