Path: blob/main/crypto/krb5/src/tests/fuzzing/fuzz_gss.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/fuzzing/fuzz_gss.c */2/*3* Copyright (C) 2024 by Arjun. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,22* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR24* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,26* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED28* OF THE POSSIBILITY OF SUCH DAMAGE.29*/3031/*32* Fuzzing harness implementation for gss_accept_sec_context.33*/3435#include "autoconf.h"36#include <krb5.h>37#include <gssapi.h>38#include <string.h>3940#define kMinInputLength 241#define kMaxInputLength 10244243extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);4445int46LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)47{48gss_OID doid;49OM_uint32 minor, ret_flags, time_rec;50gss_name_t client = GSS_C_NO_NAME;51gss_ctx_id_t context = GSS_C_NO_CONTEXT;52gss_cred_id_t deleg_cred = GSS_C_NO_CREDENTIAL;53gss_buffer_desc data_in, data_out = GSS_C_EMPTY_BUFFER;5455if (size < kMinInputLength || size > kMaxInputLength)56return 0;5758data_in.length = size;59data_in.value = (void *)data;6061gss_accept_sec_context(&minor, &context, GSS_C_NO_CREDENTIAL,62&data_in, GSS_C_NO_CHANNEL_BINDINGS, &client,63&doid, &data_out, &ret_flags, &time_rec,64&deleg_cred);6566gss_release_buffer(&minor, &data_out);6768if (context != GSS_C_NO_CONTEXT)69gss_delete_sec_context(&minor, &context, GSS_C_NO_BUFFER);7071return 0;72}737475