Blame fuzz/libpsl_load_fuzzer.c

Packit 0af36a
/*
Packit 0af36a
 * Copyright(c) 2017-2018 Tim Ruehsen
Packit 0af36a
 *
Packit 0af36a
 * Permission is hereby granted, free of charge, to any person obtaining a
Packit 0af36a
 * copy of this software and associated documentation files (the "Software"),
Packit 0af36a
 * to deal in the Software without restriction, including without limitation
Packit 0af36a
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Packit 0af36a
 * and/or sell copies of the Software, and to permit persons to whom the
Packit 0af36a
 * Software is furnished to do so, subject to the following conditions:
Packit 0af36a
 *
Packit 0af36a
 * The above copyright notice and this permission notice shall be included in
Packit 0af36a
 * all copies or substantial portions of the Software.
Packit 0af36a
 *
Packit 0af36a
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit 0af36a
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit 0af36a
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit 0af36a
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit 0af36a
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit 0af36a
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Packit 0af36a
 * DEALINGS IN THE SOFTWARE.
Packit 0af36a
 *
Packit 0af36a
 * This file is part of libpsl.
Packit 0af36a
 */
Packit 0af36a
Packit 0af36a
#include <config.h>
Packit 0af36a
Packit 0af36a
#include <assert.h> /* assert */
Packit 0af36a
Packit 0af36a
#ifdef HAVE_STDINT_H
Packit 0af36a
#include <stdint.h> /* uint8_t */
Packit 0af36a
#elif defined (_MSC_VER)
Packit 0af36a
typedef unsigned __int8 uint8_t;
Packit 0af36a
#endif
Packit 0af36a
Packit 0af36a
#include <stdlib.h> /* malloc, free */
Packit 0af36a
#include <string.h> /* memcpy */
Packit 0af36a
Packit 0af36a
#include "libpsl.h"
Packit 0af36a
#include "fuzzer.h"
Packit 0af36a
Packit 0af36a
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Packit 0af36a
{
Packit 0af36a
#ifdef HAVE_FMEMOPEN
Packit 0af36a
	FILE *fp;
Packit 0af36a
	psl_ctx_t *psl;
Packit 0af36a
Packit 0af36a
	fp = fmemopen((void *)data, size, "r");
Packit 0af36a
	if (!fp && size) /* libc6 < 2.22 return NULL when size == 0 */
Packit 0af36a
		assert(1);
Packit 0af36a
Packit 0af36a
	psl = psl_load_fp(fp);
Packit 0af36a
	psl_is_public_suffix(NULL, NULL);
Packit 0af36a
	psl_is_public_suffix(psl, ".ΓΌ.com");
Packit 0af36a
Packit 0af36a
	psl_free(psl);
Packit 0af36a
	if (fp)
Packit 0af36a
		fclose(fp);
Packit 0af36a
Packit 0af36a
	psl_load_file("/dev/null");
Packit 0af36a
#endif
Packit 0af36a
Packit 0af36a
	return 0;
Packit 0af36a
}