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 \
--- /dev/null
+#include "fuzz.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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
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)"