File: driver.c

package info (click to toggle)
tinysparql 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,528 kB
  • sloc: ansic: 119,209; python: 6,139; javascript: 725; sh: 121; perl: 106; xml: 67; makefile: 31; sql: 1
file content (54 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright 2018 LLVM contributors
 *
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 *
 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 * See https://llvm.org/LICENSE.txt for license information.
 */

/* Simpler gnu89 version of StandaloneFuzzTargetMain.c from LLVM */

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

extern int LLVMFuzzerTestOneInput (const unsigned char *data, size_t size);

int
main (int    argc,
      char **argv)
{
	FILE *f;
	long tell_result;
	size_t n_read, len;
	unsigned char *buf;
	int i;

	if (argc < 2)
		return 1;

	for (i = 1; i < argc; i++) {
		/* Empty string as argument */
		if (!*argv[i])
			continue;

		f = fopen (argv[i], "r");
		assert (f);
		fseek (f, 0, SEEK_END);
		tell_result = ftell (f);
		assert (tell_result >= 0);
		len = (size_t) tell_result;
		fseek (f, 0, SEEK_SET);
		buf = (unsigned char*) malloc (len);
		n_read = fread (buf, 1, len, f);
		assert (n_read == len);
		LLVMFuzzerTestOneInput (buf, len);

		free (buf);
		fclose (f);
	}

	printf ("Done!\n");
	return 0;
}