Path: blob/main/crypto/krb5/src/tests/fuzzing/fuzz_krad.c
34878 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/fuzzing/fuzz_krad.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 krad_packet_decode_response,33* krad_packet_decode_request.34*/3536#include "autoconf.h"37#include <k5-int.h>38#include <krad.h>3940#define kMinInputLength 241#define kMaxInputLength 10244243static krad_packet *packets[3];4445static const krad_packet *46iterator(void *data, krb5_boolean cancel)47{48krad_packet *tmp;49int *i = data;5051if (cancel || packets[*i] == NULL)52return NULL;5354tmp = packets[*i];55*i += 1;56return tmp;57}5859extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);6061int62LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)63{64int i;65krb5_context ctx;66krb5_data data_in;67const char *secret = "f";68const krad_packet *req_1 = NULL, *req_2 = NULL;69krad_packet *rsp_1 = NULL, *rsp_2 = NULL;7071if (size < kMinInputLength || size > kMaxInputLength)72return 0;7374if (krb5_init_context(&ctx) != 0)75return 0;7677data_in = make_data((void *)data, size);7879i = 0;80krad_packet_decode_response(ctx, secret, &data_in, iterator, &i,81&req_1, &rsp_1);8283i = 0;84krad_packet_decode_request(ctx, secret, &data_in, iterator, &i,85&req_2, &rsp_2);8687krad_packet_free(rsp_1);88krad_packet_free(rsp_2);89krb5_free_context(ctx);9091return 0;92}939495