Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libedit/TEST Add an LLVM fuzzing wrapper for the portabl...
details: https://anonhg.NetBSD.org/src/rev/567c121bf5ca
branches: trunk
changeset: 1023476:567c121bf5ca
user: christos <christos%NetBSD.org@localhost>
date: Fri Sep 10 13:33:45 2021 +0000
description:
Add an LLVM fuzzing wrapper for the portable libedit (Christian Holler)
diffstat:
lib/libedit/TEST/fuzz1.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)
diffs (67 lines):
diff -r 8f23ead9a6c7 -r 567c121bf5ca lib/libedit/TEST/fuzz1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libedit/TEST/fuzz1.c Fri Sep 10 13:33:45 2021 +0000
@@ -0,0 +1,63 @@
+/*
+ * build:
+ * CC=clang CXX=clang++ CFLAGS="-fsanitize=address,fuzzer-no-link -g" \
+ * CXXFLAGS="-fsanitize=address,fuzzer-no-link -g" ./configure && make
+ * run:
+ * LD_LIBRARY_PATH=../src/.libs/ .libs/fuzz1 -max_len=32 \
+ * -use_value_profile=1 -only_ascii=1
+ */
+#include <readline/readline.h>
+#include <locale.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int init = 0;
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (!Size)
+ return 0;
+
+ if (!init) {
+ setlocale(LC_CTYPE, "");
+ stifle_history(7);
+ init = 1;
+ }
+
+ clear_history();
+
+ size_t lasti = 0;
+
+ for (size_t i = 0;; ++i) {
+ if (i == Size || Data[i] == '\n') {
+ if (i - lasti) {
+ char *s = (char *)malloc(i - lasti + 1);
+ memcpy(s, &Data[lasti], i - lasti);
+ s[i - lasti] = '\0';
+
+ char *expansion;
+ int result;
+
+#ifdef DEBUG
+ fprintf(stderr, "Calling history_expand: >%s<\n", s);
+#endif
+ result = history_expand(s, &expansion);
+
+ if (result < 0 || result == 2) {
+ /* Errors ignored */
+ } else {
+ add_history(expansion);
+ }
+ free(expansion);
+ free(s);
+ }
+ lasti = i + 1;
+ }
+
+ if (i == Size)
+ break;
+ }
+
+ return 0;
+}
Home |
Main Index |
Thread Index |
Old Index