Blame fuzz/gnutls_dn_parser_fuzzer.c

Packit aea12f
/*
Packit aea12f
# Copyright 2016 Nikos Mavrogiannopoulos
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 <assert.h>
Packit aea12f
#include <stdint.h>
Packit aea12f
Packit aea12f
#include <gnutls/gnutls.h>
Packit aea12f
#include <gnutls/x509.h>
Packit aea12f
Packit aea12f
#include "fuzzer.h"
Packit aea12f
Packit aea12f
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Packit aea12f
{
Packit aea12f
	gnutls_datum_t out, raw;
Packit aea12f
	gnutls_x509_dn_t dn;
Packit aea12f
	int ret;
Packit aea12f
Packit aea12f
	raw.data = (unsigned char *)data;
Packit aea12f
	raw.size = size;
Packit aea12f
Packit aea12f
	ret = gnutls_x509_dn_init(&dn;;
Packit aea12f
	assert(ret >= 0);
Packit aea12f
Packit aea12f
	ret = gnutls_x509_dn_import(dn, &raw;;
Packit aea12f
	if (ret < 0)
Packit aea12f
		goto cleanup;
Packit aea12f
Packit aea12f
	/* If properly loaded, try to re-export in string */
Packit aea12f
	ret = gnutls_x509_dn_get_str(dn, &out;;
Packit aea12f
	if (ret < 0) {
Packit aea12f
		goto cleanup;
Packit aea12f
	}
Packit aea12f
Packit aea12f
	gnutls_free(out.data);
Packit aea12f
Packit aea12f
cleanup:
Packit aea12f
	gnutls_x509_dn_deinit(dn);
Packit aea12f
	return 0;
Packit aea12f
}