Coverage Report

Created: 2023-03-26 06:13

/src/krb5/fuzzing/Fuzz_marshal.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
16
#include "cc-int.h"
17
18
1.80k
#define kMinInputLength 10
19
897
#define kMaxInputLength 5120
20
21
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) 
22
903
{//src/lib/krb5/ccache/t_marshal.c
23
24
903
    if (Size < kMinInputLength || Size > kMaxInputLength){
25
25
        return 0;
26
25
    }
27
28
878
    int MaxVersion = 4;
29
878
    krb5_data ser_data;
30
878
    krb5_context context;
31
878
    krb5_principal princ;
32
878
    krb5_creds cred, *alloc_cred;
33
34
878
    krb5_init_context(&context);
35
36
878
    {   //public functions for unmarshalling
37
878
        ser_data = make_data((void *)Data, Size);
38
878
        krb5_unmarshal_credentials(context, &ser_data, &alloc_cred);
39
878
        krb5_free_creds(context, alloc_cred);
40
878
    }
41
42
4.39k
    for (size_t version = 1; version <= MaxVersion; version++){
43
44
3.51k
        {   //principal unmarshalling
45
3.51k
            k5_unmarshal_princ(Data, Size, version, &princ);
46
3.51k
            krb5_free_principal(context, princ);
47
3.51k
        }
48
49
3.51k
        {   //cred unmarshalling
50
3.51k
            k5_unmarshal_cred(Data, Size, version,&cred);
51
3.51k
            krb5_free_cred_contents(context, &cred);
52
3.51k
        }
53
3.51k
    }
54
55
878
    krb5_free_context(context);
56
878
    return 0;
57
903
}