From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 69A55159C9B for ; Fri, 9 Aug 2024 10:06:25 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2904B2BC0A2; Fri, 9 Aug 2024 10:06:24 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 11CAC2BC0A2 for ; Fri, 9 Aug 2024 10:06:24 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 453EA3430C2 for ; Fri, 9 Aug 2024 10:06:23 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D33D21EBD for ; Fri, 9 Aug 2024 10:06:21 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1723197977.dcd8f6a8a98c8af7e8749fe80478d42b2eeed37d.sam@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: fuzz-ar.c meson.build X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: dcd8f6a8a98c8af7e8749fe80478d42b2eeed37d X-VCS-Branch: master Date: Fri, 9 Aug 2024 10:06:21 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: fdbcf14f-2452-428f-bb63-b3eb9fa54753 X-Archives-Hash: 544a63f31e18b07b8349204c82f6355b commit: dcd8f6a8a98c8af7e8749fe80478d42b2eeed37d Author: Mike Frysinger gentoo org> AuthorDate: Fri Jan 26 04:44:54 2024 +0000 Commit: Sam James gentoo org> CommitDate: Fri Aug 9 10:06:17 2024 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=dcd8f6a8 fuzz-ar: fuzzer for the archive parsing API Signed-off-by: Mike Frysinger gentoo.org> (cherry picked from commit 4bfa4576e7b64b16937f71094641ec0f39ee47c7) Signed-off-by: Sam James gentoo.org> fuzz-ar.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ meson.build | 17 +++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/fuzz-ar.c b/fuzz-ar.c new file mode 100644 index 0000000..360194f --- /dev/null +++ b/fuzz-ar.c @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Gentoo Foundation + * Distributed under the terms of the GNU General Public License v2 + * + * Copyright 2024 Mike Frysinger - + */ + +/* 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; +} diff --git a/meson.build b/meson.build index 64fcc14..6de7a30 100644 --- a/meson.build +++ b/meson.build @@ -171,5 +171,22 @@ if do_tests and get_option('use_fuzzing') '-print_final_stats', ] ) + + fuzz_ar = executable('fuzz-ar', + common_src + ['fuzz-ar.c'], + override_options : [ + 'buildtype=debug', + ], + c_args : fuzz_flags, + link_args : fuzz_flags, + install : false + ) + test('fuzz-ar', fuzz_ar, + args : [ + '-close_fd_mask=3', + '-max_total_time=10', + '-print_final_stats=1', + ] + ) endif endif