From: Arthur Chan Date: Wed, 17 Jun 2026 19:24:46 +0000 (+0100) Subject: OSS-Fuzz: Add new fuzzers targets libsmartcols X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de5ac092b57e812ad3c4ef7f733971f6f159a9c7;p=thirdparty%2Futil-linux.git OSS-Fuzz: Add new fuzzers targets libsmartcols [kzak@redhat.com: - fix indention] Signed-off-by: Arthur Chan --- diff --git a/libsmartcols/src/Makemodule.am b/libsmartcols/src/Makemodule.am index a1f30bcde..3359e2882 100644 --- a/libsmartcols/src/Makemodule.am +++ b/libsmartcols/src/Makemodule.am @@ -105,6 +105,19 @@ libsmartcols_la_LDFLAGS += -version-info $(LIBSMARTCOLS_VERSION_INFO) EXTRA_DIST += \ libsmartcols/src/libsmartcols.sym +if FUZZING_ENGINE +check_PROGRAMS += test_smartcols_fuzz + +test_smartcols_fuzz_SOURCES = libsmartcols/src/fuzz.c + +# https://google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements +nodist_EXTRA_test_smartcols_fuzz_SOURCES = dummy.cxx + +test_smartcols_fuzz_CFLAGS = $(sample_scols_cflags) -DFUZZ_TARGET +test_smartcols_fuzz_LDFLAGS = -static +test_smartcols_fuzz_LDADD = $(sample_scols_ldadd) libcommon.la $(LIB_FUZZING_ENGINE) +endif + # move lib from $(usrlib_execdir) to $(libdir) if needed install-exec-hook-libsmartcols: if test "$(usrlib_execdir)" != "$(libdir)" -a -f "$(DESTDIR)$(usrlib_execdir)/libsmartcols.so"; then \ diff --git a/libsmartcols/src/fuzz.c b/libsmartcols/src/fuzz.c new file mode 100644 index 000000000..cb50385e4 --- /dev/null +++ b/libsmartcols/src/fuzz.c @@ -0,0 +1,65 @@ +#include "fuzz.h" + +#include +#include +#include + +#include "libsmartcols.h" + +static void process_string(const char *str) +{ + /* Parse the input as a libsmartcols filter expression. This drives the + flex scanner, the bison grammar, parameter/holder construction and the + regcomp() done for the =~ operator. */ + struct libscols_filter *fltr = scols_new_filter(str); + + scols_unref_filter(fltr); +} + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + char *str = malloc(size + 1); + if (!str) + return 0; + + memcpy(str, data, size); + str[size] = '\0'; + + process_string(str); + + free(str); + return 0; +} + +#ifndef FUZZ_TARGET +int main(int argc, char **argv) +{ + for (int i = 1; i < argc; i++) { + FILE *f = fopen(argv[i], "r"); + char *buf; + long len; + size_t n; + + if (!f) + continue; + fseek(f, 0, SEEK_END); + len = ftell(f); + fseek(f, 0, SEEK_SET); + if (len < 0) { + fclose(f); + continue; + } + buf = malloc(len + 1); + if (!buf) { + fclose(f); + continue; + } + n = fread(buf, 1, len, f); + fclose(f); + buf[n] = '\0'; + process_string(buf); + free(buf); + } + return 0; +} +#endif diff --git a/tools/oss-fuzz.sh b/tools/oss-fuzz.sh index c94a5f94d..72bdd7c6e 100755 --- a/tools/oss-fuzz.sh +++ b/tools/oss-fuzz.sh @@ -24,7 +24,7 @@ if [[ "$SANITIZER" == undefined ]]; then CXXFLAGS+=" $UBSAN_FLAGS" fi -CONFIGURE_ARGS="--disable-all-programs --enable-libuuid --enable-libfdisk --enable-last --enable-fuzzing-engine --enable-libmount --enable-libblkid" +CONFIGURE_ARGS="--disable-all-programs --enable-libuuid --enable-libfdisk --enable-last --enable-fuzzing-engine --enable-libmount --enable-libblkid --enable-libsmartcols" LIBC_VERSION="$(dpkg -s libc6 | grep Version | cut -d' ' -f2)"