Path: blob/main/crypto/krb5/src/tests/fuzzing/fuzz_krb5_ticket.c
34878 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/fuzzing/fuzz_krb5_ticket.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 krb5_decode_ticket.33*/3435#include "autoconf.h"36#include <k5-int.h>37#include <krb5.h>38#include <string.h>3940#define kMinInputLength 241#define kMaxInputLength 20484243extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);4445int46LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)47{48krb5_error_code ret;49krb5_context context = NULL;50krb5_keytab defkt = NULL;51krb5_data data_in, *data_out;52krb5_ticket *ticket = NULL;5354if (size < kMinInputLength || size > kMaxInputLength)55return 0;5657data_in = make_data((void *)data, size);5859ret = krb5_init_context(&context);60if (ret)61return 0;6263ret = krb5_kt_default(context, &defkt);64if (ret)65goto cleanup;6667ret = krb5_decode_ticket(&data_in, &ticket);68if (ret)69goto cleanup;7071ret = encode_krb5_ticket(ticket, &data_out);72if (!ret)73krb5_free_data(context, data_out);7475krb5_server_decrypt_ticket_keytab(context, defkt, ticket);7677cleanup:78krb5_free_ticket(context, ticket);79if (defkt != NULL)80krb5_kt_close(context, defkt);81krb5_free_context(context);8283return 0;84}858687