aboutsummaryrefslogtreecommitdiff
blob: 360194f393bbcba04d8dc486e49ac26216eaf1e0 (plain)
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
/*
 * Copyright 2024 Gentoo Foundation
 * Distributed under the terms of the GNU General Public License v2
 *
 * Copyright 2024 Mike Frysinger  - <vapier@gentoo.org>
 */

/* Fuzz the ar interface. */

const char argv0[] = "fuzz-ar";

#include "paxinc.h"

static int fd;

int LLVMFuzzerInitialize(int *argc, char ***argv)
{
	(void)argc;
	(void)argv;

	fd = memfd_create("fuzz-input.a", MFD_CLOEXEC);
	if (fd == -1)
		errp("memfd_create() failed");
	return 0;
}

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
	if (ftruncate(fd, size) != 0)
		errp("ftruncate(%i, %zu) failed", fd, size);
	if (pwrite(fd, data, size, 0) != (ssize_t)size)
		errp("pwrite() failed");
	if (lseek(fd, 0, SEEK_SET) != 0)
		errp("lseek() failed");

	int afd = dup(fd);
	archive_handle *ar = ar_open_fd("fuzz-input.a", afd, 0);
	if (ar == NULL) {
		close(afd);
		return 0;
	}
	while (ar_next(ar) != NULL)
		continue;

	return 0;
}