Blame fuzz/gnutls_set_trust_file_fuzzer.c

Packit aea12f
/*
Packit aea12f
# Copyright 2017 Red Hat, Inc.
Packit aea12f
#
Packit aea12f
# Licensed under the Apache License, Version 2.0 (the "License");
Packit aea12f
# you may not use this file except in compliance with the License.
Packit aea12f
# You may obtain a copy of the License at
Packit aea12f
#
Packit aea12f
#      https://www.apache.org/licenses/LICENSE-2.0
Packit aea12f
#
Packit aea12f
# Unless required by applicable law or agreed to in writing, software
Packit aea12f
# distributed under the License is distributed on an "AS IS" BASIS,
Packit aea12f
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit aea12f
# See the License for the specific language governing permissions and
Packit aea12f
# limitations under the License.
Packit aea12f
#
Packit aea12f
################################################################################
Packit aea12f
*/
Packit aea12f
Packit aea12f
#include <config.h>
Packit aea12f
Packit aea12f
#include <stdint.h>
Packit aea12f
Packit aea12f
#include <gnutls/gnutls.h>
Packit aea12f
#include "fuzzer.h"
Packit aea12f
Packit aea12f
static const uint8_t *g_data;
Packit aea12f
static size_t g_size;
Packit aea12f
Packit aea12f
#if ! defined _WIN32 && defined HAVE_FMEMOPEN
Packit aea12f
#include <stdio.h>
Packit aea12f
#include <string.h>
Packit aea12f
#include <dlfcn.h>
Packit aea12f
FILE *fopen(const char *pathname, const char *mode)
Packit aea12f
{
Packit aea12f
	FILE *(*libc_fopen)(const char *, const char *) =
Packit aea12f
		(FILE *(*)(const char *, const char *)) dlsym (RTLD_NEXT, "fopen");
Packit aea12f
Packit aea12f
	if (!strcmp(pathname, "ca_or_crl"))
Packit aea12f
		return fmemopen((void *) g_data, g_size, mode);
Packit aea12f
Packit aea12f
	return libc_fopen(pathname, mode);
Packit aea12f
}
Packit aea12f
#endif
Packit aea12f
Packit aea12f
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Packit aea12f
{
Packit aea12f
	g_data = data;
Packit aea12f
	g_size = size;
Packit aea12f
Packit aea12f
	gnutls_certificate_credentials_t creds;
Packit aea12f
	gnutls_certificate_allocate_credentials(&creds);
Packit aea12f
	gnutls_certificate_set_x509_trust_file(creds, "ca_or_crl", GNUTLS_X509_FMT_PEM);
Packit aea12f
	gnutls_certificate_set_x509_crl_file(creds, "ca_or_crl", GNUTLS_X509_FMT_PEM);
Packit aea12f
	gnutls_certificate_free_credentials(creds);
Packit aea12f
Packit aea12f
	return 0;
Packit aea12f
}