summaryrefslogtreecommitdiffstats
path: root/libmount/src/fuzz.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
commitcfe5e3905201349e9cf3f95d52ff4bd100bde37d (patch)
treed0baf160cbee3195249d095f85e52d20c21acf02 /libmount/src/fuzz.c
parentInitial commit. (diff)
downloadutil-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.tar.xz
util-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.zip
Adding upstream version 2.39.3.upstream/2.39.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libmount/src/fuzz.c')
-rw-r--r--libmount/src/fuzz.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/libmount/src/fuzz.c b/libmount/src/fuzz.c
new file mode 100644
index 0000000..2c84714
--- /dev/null
+++ b/libmount/src/fuzz.c
@@ -0,0 +1,35 @@
+#include "fuzz.h"
+#include "xalloc.h"
+#include "mountP.h"
+
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdint.h>
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ struct libmnt_table *tb = NULL;
+ FILE *f = NULL;
+
+ if (size == 0)
+ return 0;
+
+ // 128Kb should be enough to trigger all the issues we're interested in
+ if (size > 131072)
+ return 0;
+
+ tb = mnt_new_table();
+ if (!tb)
+ err_oom();
+
+ f = fmemopen((char*) data, size, "re");
+ if (!f)
+ err(EXIT_FAILURE, "fmemopen() failed");
+
+ mnt_table_enable_comments(tb, TRUE);
+ (void) mnt_table_parse_stream(tb, f, "mountinfo");
+
+ mnt_unref_table(tb);
+ fclose(f);
+
+ return 0;
+}