[gcab] Add a special binary to use just for fuzzing
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcab] Add a special binary to use just for fuzzing
- Date: Tue, 19 Dec 2017 14:18:28 +0000 (UTC)
commit 33c4c9ebdff6d0af848ecfb00adebd8eedc51c8e
Author: Richard Hughes <richard hughsie com>
Date: Tue Dec 19 14:14:52 2017 +0000
Add a special binary to use just for fuzzing
This is about twice as fast when using afl to fuzz, and can do listing and
extraction (to memory) in one pass.
README.md | 4 +--
src/gcab-fuzz.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/meson.build | 18 ++++++++++++
3 files changed, 101 insertions(+), 3 deletions(-)
---
diff --git a/README.md b/README.md
index ad24af8..8e1764c 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,4 @@ Fuzzing
CC=afl-gcc meson --default-library=static ../
AFL_HARDEN=1 ninja
- export GCAB_SKIP_CHECKSUM=1
- afl-fuzz -m 300 -i ../tests/fuzzing/ -o findings ./gcab --list-details @@
- afl-fuzz -m 300 -i ../tests/fuzzing/ -o findings2 ./gcab --directory=/tmp --extract @@
+ afl-fuzz -m 300 -i ../tests/fuzzing/ -o findings ./src/gcab-fuzz @@
diff --git a/src/gcab-fuzz.c b/src/gcab-fuzz.c
new file mode 100644
index 0000000..e66003d
--- /dev/null
+++ b/src/gcab-fuzz.c
@@ -0,0 +1,82 @@
+/*
+ * LibGCab
+ * Copyright (c) 2017, Richard Hughes <richard hughsie com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <libgcab.h>
+
+static gboolean
+_process_file (GFile *file, GError **error)
+{
+ GPtrArray *folders;
+ g_autoptr(GCabCabinet) cabinet = gcab_cabinet_new ();
+ g_autoptr(GInputStream) in = NULL;
+
+ /* load file */
+ in = G_INPUT_STREAM (g_file_read (file, NULL, error));
+ if (in == NULL) {
+ g_prefix_error (error, "Cannot open file: ");
+ return FALSE;
+ }
+ if (!gcab_cabinet_load (cabinet, in, NULL, error)) {
+ g_prefix_error (error, "Error reading: ");
+ return FALSE;
+ }
+
+ /* print file list and extract to memory */
+ folders = gcab_cabinet_get_folders (cabinet);
+ for (guint i = 0; i < folders->len; i++) {
+ GCabFolder *folder = GCAB_FOLDER (g_ptr_array_index (folders, i));
+ g_autoptr(GSList) files = gcab_folder_get_files (folder);
+ for (GSList *l = files; l != NULL; l = l->next)
+ g_print ("%s\n", gcab_file_get_name (GCAB_FILE (l->data)));
+ }
+ if (!gcab_cabinet_extract (cabinet, NULL, NULL, NULL, NULL, NULL, error)) {
+ g_prefix_error (error, "Error during extraction: ");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_autoptr(GError) error = NULL;
+
+ /* check args */
+ if (argc < 2) {
+ g_printerr ("No input files specified\n");
+ return EXIT_FAILURE;
+ }
+
+ /* try to extract each file */
+ g_setenv ("GCAB_SKIP_CHECKSUM", "1", FALSE);
+ for (gint i = 1; i < argc; i++) {
+ g_autoptr(GFile) file = g_file_new_for_commandline_arg (argv[i]);
+ if (!_process_file (file, &error)) {
+ g_printerr ("Failed to read %s: %s\n", argv[i], error->message);
+ return EXIT_FAILURE;
+ }
+ }
+
+ /* success */
+ return EXIT_SUCCESS;
+}
diff --git a/src/meson.build b/src/meson.build
index 79962ab..bd6f517 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -25,3 +25,21 @@ executable(
install : true,
install_dir : get_option('bindir')
)
+
+executable(
+ 'gcab-fuzz',
+ sources : [
+ 'gcab-fuzz.c',
+ ],
+ include_directories : [
+ include_directories('..'),
+ include_directories('../libgcab'),
+ ],
+ dependencies : [
+ gio,
+ ],
+ link_with : [
+ libgcab,
+ ],
+ c_args : cargs,
+)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]