test_fdisk_script_LDFLAGS = $(libfdisk_tests_ldflags)
test_fdisk_script_LDADD = $(libfdisk_tests_ldadd)
+if FUZZING_ENGINE
+check_PROGRAMS += test_fdisk_script_fuzz
+
+# https://google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements
+nodist_EXTRA_test_fdisk_script_fuzz_SOURCES = dummy.cxx
+
+test_fdisk_script_fuzz_SOURCES = libfdisk/src/script.c
+test_fdisk_script_fuzz_CFLAGS = -DFUZZ_TARGET $(libfdisk_la_CFLAGS) $(NO_UNUSED_WARN_CFLAGS)
+test_fdisk_script_fuzz_LDFLAGS = $(libfdisk_tests_ldflags)
+test_fdisk_script_fuzz_LDADD = $(libfdisk_tests_ldadd) $(LIB_FUZZING_ENGINE)
+endif
+
test_fdisk_version_SOURCES = libfdisk/src/version.c
test_fdisk_version_CFLAGS = $(libfdisk_tests_cflags)
test_fdisk_version_LDFLAGS = $(libfdisk_tests_ldflags)
#include "carefulputc.h"
#include "mangle.h"
+#ifdef FUZZ_TARGET
+#include "fuzz.h"
+#endif
+
/**
* SECTION: script
* @title: Script
return rc;
}
+#ifdef FUZZ_TARGET
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ char name[] = "/tmp/test-script-fuzz.XXXXXX";
+ int fd;
+ ssize_t n;
+ struct fdisk_script *dp;
+ struct fdisk_context *cxt;
+ FILE *f;
+
+ fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
+ assert(fd >= 0);
+
+ n = write(fd, data, size);
+ assert(n == (ssize_t) size);
+
+ f = fopen(name, "r");
+ assert(f);
+
+ cxt = fdisk_new_context();
+ dp = fdisk_new_script(cxt);
+
+ fdisk_script_read_file(dp, f);
+ fclose(f);
+
+ fdisk_script_write_file(dp, stdout);
+ fdisk_unref_script(dp);
+ fdisk_unref_context(cxt);
+
+ close(fd);
+ unlink(name);
+
+ return 0;
+}
+#endif
+
#ifdef TEST_PROGRAM
static int test_dump(struct fdisk_test *ts, int argc, char *argv[])
{
TS_HELPER_LIBFDISK_MKPART="${ts_helpersdir}sample-fdisk-mkpart"
TS_HELPER_LIBMOUNT_CONTEXT="${ts_helpersdir}test_mount_context"
TS_HELPER_LIBFDISK_MKPART_FULLSPEC="${ts_helpersdir}sample-fdisk-mkpart-fullspec"
+TS_HELPER_LIBFDISK_SCRIPT_FUZZ="${ts_helpersdir}test_fdisk_script_fuzz"
TS_HELPER_LIBMOUNT_LOCK="${ts_helpersdir}test_mount_lock"
TS_HELPER_LIBMOUNT_OPTSTR="${ts_helpersdir}test_mount_optstr"
TS_HELPER_LIBMOUNT_TABDIFF="${ts_helpersdir}test_mount_tab_diff"
--- /dev/null
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="test_fdisk_script_fuzz"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_HELPER_LIBFDISK_SCRIPT_FUZZ"
+
+mkdir -p ${TS_OUTPUT}_workdir
+ts_run $TS_HELPER_LIBFDISK_SCRIPT_FUZZ ${TS_OUTPUT}_workdir ${TS_SCRIPT}_files -max_total_time=10 >$TS_OUTPUT 2>$TS_ERRLOG
+
+ts_finalize
--- /dev/null
+Id=tÎ]
\ No newline at end of file
--- /dev/null
+0z
\ No newline at end of file
mkdir -p $OUT
./autogen.sh
-./configure --disable-all-programs --enable-last --enable-fuzzing-engine --enable-libmount --enable-libblkid
+./configure --disable-all-programs --enable-libuuid --enable-libfdisk --enable-last --enable-fuzzing-engine --enable-libmount --enable-libblkid
make -j$(nproc) V=1 check-programs
for d in "$(dirname $0)"/../tests/ts/fuzzers/test_*_fuzz_files; do