From 7f8c385c8fc0602d15d652ba02459da2a1351105 Mon Sep 17 00:00:00 2001 From: pdknsk Date: Fri, 12 Oct 2018 18:17:31 +0200 Subject: [PATCH] [glib] GLib: integrate into build system (#1866) * integrate into build system * remove options file * address review comment --- projects/glib/Dockerfile | 2 +- projects/glib/build.sh | 45 +++++----------------------- projects/glib/fuzz.options | 2 -- projects/glib/fuzz_bookmark.c | 8 ----- projects/glib/fuzz_dbus_message.c | 19 ------------ projects/glib/fuzz_key.c | 8 ----- projects/glib/fuzz_variant_binary.c | 12 -------- projects/glib/fuzz_variant_text.c | 12 -------- projects/glib/fuzz_variant_text.dict | 29 ------------------ projects/glib/project.yaml | 1 + 10 files changed, 9 insertions(+), 129 deletions(-) delete mode 100644 projects/glib/fuzz.options delete mode 100644 projects/glib/fuzz_bookmark.c delete mode 100644 projects/glib/fuzz_dbus_message.c delete mode 100644 projects/glib/fuzz_key.c delete mode 100644 projects/glib/fuzz_variant_binary.c delete mode 100644 projects/glib/fuzz_variant_text.c delete mode 100644 projects/glib/fuzz_variant_text.dict diff --git a/projects/glib/Dockerfile b/projects/glib/Dockerfile index 448ffd49d..a8349348c 100644 --- a/projects/glib/Dockerfile +++ b/projects/glib/Dockerfile @@ -20,4 +20,4 @@ RUN apt-get update && apt-get install -y python3-pip RUN pip3 install -U meson ninja RUN git clone --depth 1 https://gitlab.gnome.org/GNOME/glib WORKDIR glib -COPY build.sh fuzz* $SRC/ +COPY build.sh $SRC/ diff --git a/projects/glib/build.sh b/projects/glib/build.sh index a55551b85..e7e551654 100755 --- a/projects/glib/build.sh +++ b/projects/glib/build.sh @@ -21,49 +21,18 @@ rm -rf $BUILD mkdir $BUILD meson $BUILD \ + -Db_lundef=false \ -Ddefault_library=static \ -Dlibmount=false \ -Dselinux=false ninja -C $BUILD -$CC $CFLAGS -I. -Iglib -I$BUILD/glib -c $SRC/fuzz_bookmark.c -$CXX $CXXFLAGS -lFuzzingEngine \ - fuzz_bookmark.o -o $OUT/fuzz_bookmark \ - $BUILD/glib/libglib-2.0.a $BUILD/glib/libcharset/libcharset.a -cp $SRC/fuzz.options $OUT/fuzz_bookmark.options -find glib/tests -type f -size -32k -name "*.xbel" \ - -exec zip -qju $OUT/fuzz_bookmark_seed_corpus.zip "{}" \; +find $BUILD/fuzzing -maxdepth 1 -executable -type f -exec cp "{}" $OUT \; -$CC $CFLAGS -I. -Iglib -I$BUILD/glib -c $SRC/fuzz_key.c -$CXX $CXXFLAGS -lFuzzingEngine \ - fuzz_key.o -o $OUT/fuzz_key \ - $BUILD/glib/libglib-2.0.a $BUILD/glib/libcharset/libcharset.a -cp $SRC/fuzz.options $OUT/fuzz_key.options -find gio/tests -type f -size -32k -name "*.desktop" \ - -exec zip -qju $OUT/fuzz_key_seed_corpus.zip "{}" \; +find fuzzing -type f -name "*.dict" -exec cp "{}" $OUT \; -$CC $CFLAGS -I. -Iglib -I$BUILD/glib -c $SRC/fuzz_variant_text.c -$CXX $CXXFLAGS -lFuzzingEngine \ - fuzz_variant_text.o -o $OUT/fuzz_variant_text \ - $BUILD/glib/libglib-2.0.a $BUILD/glib/libcharset/libcharset.a -cp $SRC/fuzz.options $OUT/fuzz_variant_text.options -cp $SRC/fuzz_variant_text.dict $OUT - -$CC $CFLAGS -I. -Iglib -I$BUILD/glib -c $SRC/fuzz_variant_binary.c -$CXX $CXXFLAGS -lFuzzingEngine \ - fuzz_variant_binary.o -o $OUT/fuzz_variant_binary \ - $BUILD/glib/libglib-2.0.a $BUILD/glib/libcharset/libcharset.a -cp $SRC/fuzz.options $OUT/fuzz_variant_binary.options - -$CC $CFLAGS -I. -Iglib -Igmodule -I$BUILD -I$BUILD/glib \ - -c $SRC/fuzz_dbus_message.c -$CXX $CXXFLAGS -lFuzzingEngine \ - fuzz_dbus_message.o -o $OUT/fuzz_dbus_message \ - $BUILD/gio/libgio-2.0.a $BUILD/gmodule/libgmodule-2.0.a \ - $BUILD/gobject/libgobject-2.0.a $BUILD/glib/libglib-2.0.a \ - $BUILD/glib/libcharset/libcharset.a $BUILD/glib/pcre/libpcre.a \ - $BUILD/gio/xdgmime/libxdgmime.a $BUILD/gio/inotify/libinotify.a \ - $BUILD/subprojects/zlib*/libz.a $BUILD/subprojects/libffi/src/libffi.a \ - -Bstatic -lresolv -cp $SRC/fuzz.options $OUT/fuzz_dbus_message.options +for CORPUS in $(find fuzzing -type f -name "*.corpus"); do + BASENAME=${CORPUS##*/} + zip $OUT/${BASENAME%%.*}_seed_corpus.zip . -ws -r -i@$CORPUS +done diff --git a/projects/glib/fuzz.options b/projects/glib/fuzz.options deleted file mode 100644 index 7ca5e76f5..000000000 --- a/projects/glib/fuzz.options +++ /dev/null @@ -1,2 +0,0 @@ -[libfuzzer] -close_fd_mask = 2 diff --git a/projects/glib/fuzz_bookmark.c b/projects/glib/fuzz_bookmark.c deleted file mode 100644 index 1b14a1d66..000000000 --- a/projects/glib/fuzz_bookmark.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "glib/glib.h" -#include - -int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - g_autoptr(GBookmarkFile) bookmarkfile = g_bookmark_file_new(); - g_bookmark_file_load_from_data(bookmarkfile, (const gchar*)data, size, NULL); - return 0; -} diff --git a/projects/glib/fuzz_dbus_message.c b/projects/glib/fuzz_dbus_message.c deleted file mode 100644 index 8531e604d..000000000 --- a/projects/glib/fuzz_dbus_message.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "gio/gio.h" -#include - -static GDBusCapabilityFlags flags = G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING; - -int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - gssize bytes = g_dbus_message_bytes_needed((guchar*)data, size, NULL); - if (bytes <= 0 || bytes > (100 << 20)) - return 0; - - g_autoptr(GDBusMessage) msg = - g_dbus_message_new_from_blob((guchar*)data, size, flags, NULL); - if (!msg) - return 0; - - gsize msg_size; - g_autofree guchar* blob = g_dbus_message_to_blob(msg, &msg_size, flags, NULL); - return 0; -} diff --git a/projects/glib/fuzz_key.c b/projects/glib/fuzz_key.c deleted file mode 100644 index 839ab9de2..000000000 --- a/projects/glib/fuzz_key.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "glib/glib.h" -#include - -int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - g_autoptr(GKeyFile) keyfile = g_key_file_new(); - g_key_file_load_from_data(keyfile, (const gchar*)data, size, 0, NULL); - return 0; -} diff --git a/projects/glib/fuzz_variant_binary.c b/projects/glib/fuzz_variant_binary.c deleted file mode 100644 index cbe54d9c9..000000000 --- a/projects/glib/fuzz_variant_binary.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "glib/glib.h" -#include - -int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - g_autoptr(GVariant) variant = g_variant_new_from_data( - G_VARIANT_TYPE_VARIANT, data, size, FALSE, NULL, NULL); - if (!variant) - return 0; - g_variant_get_normal_form(variant); - g_variant_get_data(variant); - return 0; -} diff --git a/projects/glib/fuzz_variant_text.c b/projects/glib/fuzz_variant_text.c deleted file mode 100644 index 249ad1986..000000000 --- a/projects/glib/fuzz_variant_text.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "glib/glib.h" -#include - -int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - const gchar* gdata = (const gchar*)data; - g_autoptr(GVariant) variant = - g_variant_parse(NULL, gdata, gdata + size, NULL, NULL); - if (!variant) - return 0; - g_autofree gchar* text = g_variant_print(variant, TRUE); - return 0; -} diff --git a/projects/glib/fuzz_variant_text.dict b/projects/glib/fuzz_variant_text.dict deleted file mode 100644 index 75c8ec611..000000000 --- a/projects/glib/fuzz_variant_text.dict +++ /dev/null @@ -1,29 +0,0 @@ -"'" -"(" -")" -"<" -">" -"[" -"]" -"{" -"}" -"*" -"?" -"@" -"boolean" -"byte" -"double" -"false" -"handle" -"int16" -"int32" -"int64" -"just" -"nothing" -"objectpath" -"signature" -"string" -"true" -"uint16" -"uint32" -"uint64" diff --git a/projects/glib/project.yaml b/projects/glib/project.yaml index 6757dcda0..90a03d0c1 100644 --- a/projects/glib/project.yaml +++ b/projects/glib/project.yaml @@ -8,3 +8,4 @@ sanitizers: - address - undefined - memory +help_url: https://gitlab.gnome.org/GNOME/glib/tree/master/fuzzing#how-to-reproduce-oss-fuzz-bugs-locally