Coverage Report

Created: 2023-06-29 06:57

/src/krb5/fuzzing/Fuzz_gss_accept_sec_context.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2023 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 <string.h>
13
14
#include "krb5.h"
15
#include "gssapi.h"
16
17
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
18
1.56k
{
19
1.56k
    OM_uint32 maj_stat, min_stat;
20
21
1.56k
    gss_ctx_id_t ctx = GSS_C_NO_CONTEXT;
22
1.56k
    gss_name_t client_name = GSS_C_NO_NAME;
23
1.56k
    gss_cred_id_t deleg_cred = GSS_C_NO_CREDENTIAL;
24
25
    /* Each fuzz input contains multiple tokens preceded by a length field.
26
     * Process them in turn with gss_accept_sec_context while
27
     * GSS_S_CONTINUE_NEEDED is set
28
     */
29
1.56k
    do {
30
1.56k
        unsigned short token_length;
31
32
1.56k
        gss_buffer_desc input_token, output_token = GSS_C_EMPTY_BUFFER;
33
34
1.56k
        if (Size < sizeof(token_length))
35
1
            break;
36
37
1.56k
        token_length = *(unsigned short *)Data;
38
39
1.56k
        Data += sizeof(token_length);
40
1.56k
        Size -= sizeof(token_length);
41
42
1.56k
        if (token_length == 0 || token_length > Size)
43
22
            break;
44
45
1.54k
        input_token.length = token_length;
46
1.54k
        input_token.value = malloc(token_length);
47
1.54k
        memcpy(input_token.value, Data, token_length);
48
49
1.54k
        Data += token_length;
50
1.54k
        Size -= token_length;
51
52
1.54k
        maj_stat = gss_accept_sec_context(
53
1.54k
            &min_stat,
54
1.54k
            &ctx,
55
1.54k
            GSS_C_NO_CREDENTIAL, /* server_creds */
56
1.54k
            &input_token,
57
1.54k
            GSS_C_NO_CHANNEL_BINDINGS, /* input_bindings */
58
1.54k
            &client_name,
59
1.54k
            NULL, /* mech_type */
60
1.54k
            &output_token,
61
1.54k
            NULL, /* ret_flags */
62
1.54k
            NULL, /* time */
63
1.54k
            &deleg_cred
64
1.54k
        );
65
66
1.54k
        gss_release_buffer(&min_stat, &output_token);
67
1.54k
        gss_release_buffer(&min_stat, &input_token);
68
69
1.54k
        if (GSS_ERROR(maj_stat)) {
70
1.54k
            if (ctx != GSS_C_NO_CONTEXT)
71
0
                gss_delete_sec_context(&min_stat, &ctx, GSS_C_NO_BUFFER);
72
1.54k
            break;
73
1.54k
        }
74
1.54k
    } while(maj_stat & GSS_S_CONTINUE_NEEDED);
75
76
0
    gss_release_name(&min_stat, &client_name);
77
1.56k
    gss_release_cred(&min_stat, &deleg_cred);
78
79
1.56k
    return 0;
80
1.56k
}