From f2992af1efee787c61051562d43967333fc95305 Mon Sep 17 00:00:00 2001 From: m5cn9itjr <295305452@qq.com> Date: Wed, 16 Oct 2024 20:27:14 +0800 Subject: [PATCH] ADD file via upload --- argv-fuzz-inl.h | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 argv-fuzz-inl.h diff --git a/argv-fuzz-inl.h b/argv-fuzz-inl.h new file mode 100644 index 0000000..e0e28e1 --- /dev/null +++ b/argv-fuzz-inl.h @@ -0,0 +1,91 @@ +/* + Copyright 2015 Google LLC All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +/* + american fuzzy lop - sample argv fuzzing wrapper + ------------------------------------------------ + + Written by Michal Zalewski + + This file shows a simple way to fuzz command-line parameters with stock + afl-fuzz. To use, add: + + #include "/path/to/argv-fuzz-inl.h" + + ...to the file containing main(), ideally placing it after all the + standard includes. Next, put AFL_INIT_ARGV(); near the very beginning of + main(). + + This will cause the program to read NUL-delimited input from stdin and + put it in argv[]. Two subsequent NULs terminate the array. + + If you would like to always preserve argv[0], use this instead: + AFL_INIT_SET0("prog_name"); +*/ + +#ifndef _HAVE_ARGV_FUZZ_INL +#define _HAVE_ARGV_FUZZ_INL + +#include +#include + +#define AFL_INIT_ARGV() do { argv = afl_init_argv(&argc); } while (0) + +#define AFL_INIT_SET0(_p) do { \ + argv = afl_init_argv(&argc); \ + argv[0] = (_p); \ + if (!argc) argc = 1; \ + } while (0) + +#define MAX_CMDLINE_LEN 100000 +#define MAX_CMDLINE_PAR 1000 + +static char** afl_init_argv(int* argc) { + + static char in_buf[MAX_CMDLINE_LEN]; + static char* ret[MAX_CMDLINE_PAR]; + + char* ptr = in_buf; + int rc = 1; /* start after argv[0] */ + + if (read(0, in_buf, MAX_CMDLINE_LEN - 2) < 0); + + while (*ptr) { + + ret[rc] = ptr; + + /* insert '\0' at the end of ret[rc] on first space-sym */ + while (*ptr && !isspace(*ptr)) ptr++; + *ptr = '\0'; + ptr++; + + /* skip more space-syms */ + while (*ptr && isspace(*ptr)) ptr++; + + rc++; + } + + *argc = rc; + + return ret; + +} + +#undef MAX_CMDLINE_LEN +#undef MAX_CMDLINE_PAR + +#endif /* !_HAVE_ARGV_FUZZ_INL */