mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Merge pull request #4987 from kittywhiskers/fuzz4
backport: bitcoin#18736, #19379, #19296, #18775, #20188, #19558, #18445, #18744, #19067, #19065 (fuzzing harness backports: part 4)
This commit is contained in:
commit
7bb30f57c8
@ -1,5 +1,5 @@
|
||||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
|
||||
# https://www.gnu.org/software/autoconf-archive/ax_pthread.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
@ -55,6 +55,7 @@
|
||||
#
|
||||
# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
|
||||
# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
|
||||
# Copyright (c) 2019 Marc Stevens <marc.stevens@cwi.nl>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
@ -67,7 +68,7 @@
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
@ -82,7 +83,7 @@
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 23
|
||||
#serial 27
|
||||
|
||||
AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
|
||||
AC_DEFUN([AX_PTHREAD], [
|
||||
@ -123,10 +124,12 @@ fi
|
||||
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
|
||||
# libraries is broken (non-POSIX).
|
||||
|
||||
# Create a list of thread flags to try. Items starting with a "-" are
|
||||
# C compiler flags, and other items are library names, except for "none"
|
||||
# which indicates that we try without any flags at all, and "pthread-config"
|
||||
# which is a program returning the flags for the Pth emulation library.
|
||||
# Create a list of thread flags to try. Items with a "," contain both
|
||||
# C compiler flags (before ",") and linker flags (after ","). Other items
|
||||
# starting with a "-" are C compiler flags, and remaining items are
|
||||
# library names, except for "none" which indicates that we try without
|
||||
# any flags at all, and "pthread-config" which is a program returning
|
||||
# the flags for the Pth emulation library.
|
||||
|
||||
ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
|
||||
|
||||
@ -194,14 +197,47 @@ case $host_os in
|
||||
# that too in a future libc.) So we'll check first for the
|
||||
# standard Solaris way of linking pthreads (-mt -lpthread).
|
||||
|
||||
ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags"
|
||||
ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Are we compiling with Clang?
|
||||
|
||||
AC_CACHE_CHECK([whether $CC is Clang],
|
||||
[ax_cv_PTHREAD_CLANG],
|
||||
[ax_cv_PTHREAD_CLANG=no
|
||||
# Note that Autoconf sets GCC=yes for Clang as well as GCC
|
||||
if test "x$GCC" = "xyes"; then
|
||||
AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG],
|
||||
[/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
|
||||
# if defined(__clang__) && defined(__llvm__)
|
||||
AX_PTHREAD_CC_IS_CLANG
|
||||
# endif
|
||||
],
|
||||
[ax_cv_PTHREAD_CLANG=yes])
|
||||
fi
|
||||
])
|
||||
ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
|
||||
|
||||
|
||||
# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
|
||||
|
||||
# Note that for GCC and Clang -pthread generally implies -lpthread,
|
||||
# except when -nostdlib is passed.
|
||||
# This is problematic using libtool to build C++ shared libraries with pthread:
|
||||
# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460
|
||||
# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333
|
||||
# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555
|
||||
# To solve this, first try -pthread together with -lpthread for GCC
|
||||
|
||||
AS_IF([test "x$GCC" = "xyes"],
|
||||
[ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"])
|
||||
[ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"])
|
||||
|
||||
# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first
|
||||
|
||||
AS_IF([test "x$ax_pthread_clang" = "xyes"],
|
||||
[ax_pthread_flags="-pthread,-lpthread -pthread"])
|
||||
|
||||
|
||||
# The presence of a feature test macro requesting re-entrant function
|
||||
# definitions is, on some systems, a strong hint that pthreads support is
|
||||
@ -224,25 +260,86 @@ AS_IF([test "x$ax_pthread_check_macro" = "x--"],
|
||||
[ax_pthread_check_cond=0],
|
||||
[ax_pthread_check_cond="!defined($ax_pthread_check_macro)"])
|
||||
|
||||
# Are we compiling with Clang?
|
||||
|
||||
AC_CACHE_CHECK([whether $CC is Clang],
|
||||
[ax_cv_PTHREAD_CLANG],
|
||||
[ax_cv_PTHREAD_CLANG=no
|
||||
# Note that Autoconf sets GCC=yes for Clang as well as GCC
|
||||
if test "x$GCC" = "xyes"; then
|
||||
AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG],
|
||||
[/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
|
||||
# if defined(__clang__) && defined(__llvm__)
|
||||
AX_PTHREAD_CC_IS_CLANG
|
||||
# endif
|
||||
],
|
||||
[ax_cv_PTHREAD_CLANG=yes])
|
||||
fi
|
||||
])
|
||||
ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
|
||||
if test "x$ax_pthread_ok" = "xno"; then
|
||||
for ax_pthread_try_flag in $ax_pthread_flags; do
|
||||
|
||||
case $ax_pthread_try_flag in
|
||||
none)
|
||||
AC_MSG_CHECKING([whether pthreads work without any flags])
|
||||
;;
|
||||
|
||||
*,*)
|
||||
PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"`
|
||||
PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"`
|
||||
AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"])
|
||||
;;
|
||||
|
||||
-*)
|
||||
AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag])
|
||||
PTHREAD_CFLAGS="$ax_pthread_try_flag"
|
||||
;;
|
||||
|
||||
pthread-config)
|
||||
AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
|
||||
AS_IF([test "x$ax_pthread_config" = "xno"], [continue])
|
||||
PTHREAD_CFLAGS="`pthread-config --cflags`"
|
||||
PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
|
||||
;;
|
||||
|
||||
*)
|
||||
AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag])
|
||||
PTHREAD_LIBS="-l$ax_pthread_try_flag"
|
||||
;;
|
||||
esac
|
||||
|
||||
ax_pthread_save_CFLAGS="$CFLAGS"
|
||||
ax_pthread_save_LIBS="$LIBS"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
LIBS="$PTHREAD_LIBS $LIBS"
|
||||
|
||||
# Check for various functions. We must include pthread.h,
|
||||
# since some functions may be macros. (On the Sequent, we
|
||||
# need a special flag -Kthread to make this header compile.)
|
||||
# We check for pthread_join because it is in -lpthread on IRIX
|
||||
# while pthread_create is in libc. We check for pthread_attr_init
|
||||
# due to DEC craziness with -lpthreads. We check for
|
||||
# pthread_cleanup_push because it is one of the few pthread
|
||||
# functions on Solaris that doesn't have a non-functional libc stub.
|
||||
# We try pthread_create on general principles.
|
||||
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
|
||||
# if $ax_pthread_check_cond
|
||||
# error "$ax_pthread_check_macro must be defined"
|
||||
# endif
|
||||
static void *some_global = NULL;
|
||||
static void routine(void *a)
|
||||
{
|
||||
/* To avoid any unused-parameter or
|
||||
unused-but-set-parameter warning. */
|
||||
some_global = a;
|
||||
}
|
||||
static void *start_routine(void *a) { return a; }],
|
||||
[pthread_t th; pthread_attr_t attr;
|
||||
pthread_create(&th, 0, start_routine, 0);
|
||||
pthread_join(th, 0);
|
||||
pthread_attr_init(&attr);
|
||||
pthread_cleanup_push(routine, 0);
|
||||
pthread_cleanup_pop(0) /* ; */])],
|
||||
[ax_pthread_ok=yes],
|
||||
[])
|
||||
|
||||
CFLAGS="$ax_pthread_save_CFLAGS"
|
||||
LIBS="$ax_pthread_save_LIBS"
|
||||
|
||||
AC_MSG_RESULT([$ax_pthread_ok])
|
||||
AS_IF([test "x$ax_pthread_ok" = "xyes"], [break])
|
||||
|
||||
PTHREAD_LIBS=""
|
||||
PTHREAD_CFLAGS=""
|
||||
done
|
||||
fi
|
||||
|
||||
ax_pthread_clang_warning=no
|
||||
|
||||
# Clang needs special handling, because older versions handle the -pthread
|
||||
# option in a rather... idiosyncratic way
|
||||
@ -261,11 +358,6 @@ if test "x$ax_pthread_clang" = "xyes"; then
|
||||
# -pthread does define _REENTRANT, and while the Darwin headers
|
||||
# ignore this macro, third-party headers might not.)
|
||||
|
||||
PTHREAD_CFLAGS="-pthread"
|
||||
PTHREAD_LIBS=
|
||||
|
||||
ax_pthread_ok=yes
|
||||
|
||||
# However, older versions of Clang make a point of warning the user
|
||||
# that, in an invocation where only linking and no compilation is
|
||||
# taking place, the -pthread option has no effect ("argument unused
|
||||
@ -320,78 +412,7 @@ if test "x$ax_pthread_clang" = "xyes"; then
|
||||
|
||||
fi # $ax_pthread_clang = yes
|
||||
|
||||
if test "x$ax_pthread_ok" = "xno"; then
|
||||
for ax_pthread_try_flag in $ax_pthread_flags; do
|
||||
|
||||
case $ax_pthread_try_flag in
|
||||
none)
|
||||
AC_MSG_CHECKING([whether pthreads work without any flags])
|
||||
;;
|
||||
|
||||
-mt,pthread)
|
||||
AC_MSG_CHECKING([whether pthreads work with -mt -lpthread])
|
||||
PTHREAD_CFLAGS="-mt"
|
||||
PTHREAD_LIBS="-lpthread"
|
||||
;;
|
||||
|
||||
-*)
|
||||
AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag])
|
||||
PTHREAD_CFLAGS="$ax_pthread_try_flag"
|
||||
;;
|
||||
|
||||
pthread-config)
|
||||
AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
|
||||
AS_IF([test "x$ax_pthread_config" = "xno"], [continue])
|
||||
PTHREAD_CFLAGS="`pthread-config --cflags`"
|
||||
PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
|
||||
;;
|
||||
|
||||
*)
|
||||
AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag])
|
||||
PTHREAD_LIBS="-l$ax_pthread_try_flag"
|
||||
;;
|
||||
esac
|
||||
|
||||
ax_pthread_save_CFLAGS="$CFLAGS"
|
||||
ax_pthread_save_LIBS="$LIBS"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
LIBS="$PTHREAD_LIBS $LIBS"
|
||||
|
||||
# Check for various functions. We must include pthread.h,
|
||||
# since some functions may be macros. (On the Sequent, we
|
||||
# need a special flag -Kthread to make this header compile.)
|
||||
# We check for pthread_join because it is in -lpthread on IRIX
|
||||
# while pthread_create is in libc. We check for pthread_attr_init
|
||||
# due to DEC craziness with -lpthreads. We check for
|
||||
# pthread_cleanup_push because it is one of the few pthread
|
||||
# functions on Solaris that doesn't have a non-functional libc stub.
|
||||
# We try pthread_create on general principles.
|
||||
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
|
||||
# if $ax_pthread_check_cond
|
||||
# error "$ax_pthread_check_macro must be defined"
|
||||
# endif
|
||||
static void routine(void *a) { a = 0; }
|
||||
static void *start_routine(void *a) { return a; }],
|
||||
[pthread_t th; pthread_attr_t attr;
|
||||
pthread_create(&th, 0, start_routine, 0);
|
||||
pthread_join(th, 0);
|
||||
pthread_attr_init(&attr);
|
||||
pthread_cleanup_push(routine, 0);
|
||||
pthread_cleanup_pop(0) /* ; */])],
|
||||
[ax_pthread_ok=yes],
|
||||
[])
|
||||
|
||||
CFLAGS="$ax_pthread_save_CFLAGS"
|
||||
LIBS="$ax_pthread_save_LIBS"
|
||||
|
||||
AC_MSG_RESULT([$ax_pthread_ok])
|
||||
AS_IF([test "x$ax_pthread_ok" = "xyes"], [break])
|
||||
|
||||
PTHREAD_LIBS=""
|
||||
PTHREAD_CFLAGS=""
|
||||
done
|
||||
fi
|
||||
|
||||
# Various other checks:
|
||||
if test "x$ax_pthread_ok" = "xyes"; then
|
||||
@ -438,7 +459,8 @@ if test "x$ax_pthread_ok" = "xyes"; then
|
||||
AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
|
||||
[ax_cv_PTHREAD_PRIO_INHERIT],
|
||||
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
|
||||
[[int i = PTHREAD_PRIO_INHERIT;]])],
|
||||
[[int i = PTHREAD_PRIO_INHERIT;
|
||||
return i;]])],
|
||||
[ax_cv_PTHREAD_PRIO_INHERIT=yes],
|
||||
[ax_cv_PTHREAD_PRIO_INHERIT=no])
|
||||
])
|
||||
|
@ -1863,10 +1863,10 @@ echo " target os = $TARGET_OS"
|
||||
echo " build os = $BUILD_OS"
|
||||
echo
|
||||
echo " CC = $CC"
|
||||
echo " CFLAGS = $CFLAGS"
|
||||
echo " CFLAGS = $PTHREAD_CFLAGS $CFLAGS"
|
||||
echo " CPPFLAGS = $DEBUG_CPPFLAGS $HARDENED_CPPFLAGS $CPPFLAGS"
|
||||
echo " CXX = $CXX"
|
||||
echo " CXXFLAGS = $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CXXFLAGS"
|
||||
echo " LDFLAGS = $PTHREAD_CFLAGS $HARDENED_LDFLAGS $GPROF_LDFLAGS $LDFLAGS"
|
||||
echo " LDFLAGS = $PTHREAD_LIBS $HARDENED_LDFLAGS $GPROF_LDFLAGS $LDFLAGS"
|
||||
echo " ARFLAGS = $ARFLAGS"
|
||||
echo
|
||||
|
@ -5,10 +5,11 @@
|
||||
|
||||
DIST_SUBDIRS = secp256k1
|
||||
|
||||
AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS)
|
||||
AM_LDFLAGS = $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS)
|
||||
AM_CXXFLAGS = $(DEBUG_CXXFLAGS) $(HARDENED_CXXFLAGS) $(WARN_CXXFLAGS) $(NOWARN_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS)
|
||||
AM_CPPFLAGS = $(DEBUG_CPPFLAGS) $(HARDENED_CPPFLAGS)
|
||||
AM_LIBTOOLFLAGS = --preserve-dup-deps
|
||||
PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)
|
||||
EXTRA_LIBRARIES =
|
||||
|
||||
if ENABLE_STACKTRACES
|
||||
@ -741,7 +742,7 @@ nodist_libbitcoin_util_a_SOURCES = $(srcdir)/obj/build.h
|
||||
dashd_SOURCES = bitcoind.cpp
|
||||
dashd_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
dashd_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
dashd_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
dashd_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
|
||||
|
||||
if TARGET_WINDOWS
|
||||
dashd_SOURCES += dashd-res.rc
|
||||
@ -770,7 +771,7 @@ dashd_LDADD += $(BACKTRACE_LIB) $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NA
|
||||
dash_cli_SOURCES = bitcoin-cli.cpp
|
||||
dash_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS)
|
||||
dash_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
dash_cli_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
dash_cli_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
|
||||
|
||||
if TARGET_WINDOWS
|
||||
dash_cli_SOURCES += dash-cli-res.rc
|
||||
@ -788,7 +789,7 @@ dash_cli_LDADD += $(BACKTRACE_LIB) $(BOOST_LIBS) $(EVENT_LIBS) $(BLS_LIBS) $(GMP
|
||||
dash_tx_SOURCES = bitcoin-tx.cpp
|
||||
dash_tx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
dash_tx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
dash_tx_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
dash_tx_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
|
||||
|
||||
if TARGET_WINDOWS
|
||||
dash_tx_SOURCES += dash-tx-res.rc
|
||||
@ -809,7 +810,7 @@ dash_tx_LDADD += $(BACKTRACE_LIB) $(BOOST_LIBS) $(BLS_LIBS) $(GMP_LIBS)
|
||||
dash_wallet_SOURCES = bitcoin-wallet.cpp
|
||||
dash_wallet_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
dash_wallet_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
dash_wallet_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
dash_wallet_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
|
||||
|
||||
if TARGET_WINDOWS
|
||||
dash_wallet_SOURCES += dash-wallet-res.rc
|
||||
|
@ -79,7 +79,7 @@ bench_bench_dash_SOURCES += bench/wallet_balance.cpp
|
||||
endif
|
||||
|
||||
bench_bench_dash_LDADD += $(BACKTRACE_LIB) $(BOOST_LIBS) $(BDB_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(BLS_LIBS) $(GMP_LIBS)
|
||||
bench_bench_dash_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
bench_bench_dash_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
|
||||
|
||||
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)
|
||||
|
||||
|
@ -391,7 +391,7 @@ endif
|
||||
qt_dash_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
|
||||
$(BACKTRACE_LIB) $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBSECP256K1) \
|
||||
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS) $(GMP_LIBS)
|
||||
qt_dash_qt_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
qt_dash_qt_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
|
||||
qt_dash_qt_LIBTOOLFLAGS = $(AM_LIBTOOLFLAGS) --tag CXX
|
||||
|
||||
#locale/foo.ts -> locale/foo.qm
|
||||
|
@ -61,7 +61,7 @@ qt_test_test_dash_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOI
|
||||
$(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BACKTRACE_LIB) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
|
||||
$(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBSECP256K1) \
|
||||
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS) $(GMP_LIBS)
|
||||
qt_test_test_dash_qt_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
qt_test_test_dash_qt_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
|
||||
qt_test_test_dash_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
|
||||
|
||||
CLEAN_BITCOIN_QT_TEST = $(TEST_QT_MOC_CPP) qt/test/*.gcda qt/test/*.gcno
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -31,7 +31,7 @@ static secp256k1_context* secp256k1_context_sign = nullptr;
|
||||
*
|
||||
* out32 must point to an output buffer of length at least 32 bytes.
|
||||
*/
|
||||
static int ec_seckey_import_der(const secp256k1_context* ctx, unsigned char *out32, const unsigned char *seckey, size_t seckeylen) {
|
||||
int ec_seckey_import_der(const secp256k1_context* ctx, unsigned char *out32, const unsigned char *seckey, size_t seckeylen) {
|
||||
const unsigned char *end = seckey + seckeylen;
|
||||
memset(out32, 0, 32);
|
||||
/* sequence header */
|
||||
@ -88,7 +88,7 @@ static int ec_seckey_import_der(const secp256k1_context* ctx, unsigned char *out
|
||||
* will be set to the number of bytes used in the buffer.
|
||||
* key32 must point to a 32-byte raw private key.
|
||||
*/
|
||||
static int ec_seckey_export_der(const secp256k1_context *ctx, unsigned char *seckey, size_t *seckeylen, const unsigned char *key32, bool compressed) {
|
||||
int ec_seckey_export_der(const secp256k1_context *ctx, unsigned char *seckey, size_t *seckeylen, const unsigned char *key32, bool compressed) {
|
||||
assert(*seckeylen >= CKey::SIZE);
|
||||
secp256k1_pubkey pubkey;
|
||||
size_t pubkeylen = 0;
|
||||
|
@ -24,7 +24,7 @@ secp256k1_context* secp256k1_context_verify = nullptr;
|
||||
* strict DER before being passed to this module, and we know it supports all
|
||||
* violations present in the blockchain before that point.
|
||||
*/
|
||||
static int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
|
||||
int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
|
||||
size_t rpos, rlen, spos, slen;
|
||||
size_t pos = 0;
|
||||
size_t lenbyte;
|
||||
|
119
src/test/fuzz/addrman.cpp
Normal file
119
src/test/fuzz/addrman.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <addrdb.h>
|
||||
#include <addrman.h>
|
||||
#include <chainparams.h>
|
||||
#include <merkleblock.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <time.h>
|
||||
#include <util/asmap.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void initialize()
|
||||
{
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
}
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
CAddrMan addr_man;
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
addr_man.m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
|
||||
if (!SanityCheckASMap(addr_man.m_asmap)) {
|
||||
addr_man.m_asmap.clear();
|
||||
}
|
||||
}
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 11)) {
|
||||
case 0: {
|
||||
addr_man.Clear();
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
addr_man.ResolveCollisions();
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
(void)addr_man.SelectTriedCollision();
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
(void)addr_man.Select(fuzzed_data_provider.ConsumeBool());
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
(void)addr_man.GetAddr();
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
const std::optional<CAddress> opt_address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
|
||||
const std::optional<CNetAddr> opt_net_addr = ConsumeDeserializable<CNetAddr>(fuzzed_data_provider);
|
||||
if (opt_address && opt_net_addr) {
|
||||
addr_man.Add(*opt_address, *opt_net_addr, fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(0, 100000000));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
std::vector<CAddress> addresses;
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
const std::optional<CAddress> opt_address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
|
||||
if (!opt_address) {
|
||||
break;
|
||||
}
|
||||
addresses.push_back(*opt_address);
|
||||
}
|
||||
const std::optional<CNetAddr> opt_net_addr = ConsumeDeserializable<CNetAddr>(fuzzed_data_provider);
|
||||
if (opt_net_addr) {
|
||||
addr_man.Add(addresses, *opt_net_addr, fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(0, 100000000));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
|
||||
if (opt_service) {
|
||||
addr_man.Good(*opt_service, fuzzed_data_provider.ConsumeBool(), ConsumeTime(fuzzed_data_provider));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
|
||||
if (opt_service) {
|
||||
addr_man.Attempt(*opt_service, fuzzed_data_provider.ConsumeBool(), ConsumeTime(fuzzed_data_provider));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 9: {
|
||||
const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
|
||||
if (opt_service) {
|
||||
addr_man.Connected(*opt_service, ConsumeTime(fuzzed_data_provider));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
|
||||
if (opt_service) {
|
||||
addr_man.SetServices(*opt_service, ServiceFlags{fuzzed_data_provider.ConsumeIntegral<uint64_t>()});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 11: {
|
||||
(void)addr_man.Check();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)addr_man.size();
|
||||
CDataStream data_stream(SER_NETWORK, PROTOCOL_VERSION);
|
||||
data_stream << addr_man;
|
||||
}
|
@ -55,4 +55,8 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
const size_t raw_memory_size = RecursiveDynamicUsage(block);
|
||||
const size_t raw_memory_size_as_shared_ptr = RecursiveDynamicUsage(std::make_shared<CBlock>(block));
|
||||
assert(raw_memory_size_as_shared_ptr > raw_memory_size);
|
||||
CBlock block_copy = block;
|
||||
block_copy.SetNull();
|
||||
const bool is_null = block_copy.IsNull();
|
||||
assert(is_null);
|
||||
}
|
||||
|
65
src/test/fuzz/chain.cpp
Normal file
65
src/test/fuzz/chain.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <chain.h>
|
||||
#include <optional.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
Optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider);
|
||||
if (!disk_block_index) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint256 zero{};
|
||||
disk_block_index->phashBlock = &zero;
|
||||
(void)disk_block_index->GetBlockHash();
|
||||
(void)disk_block_index->GetBlockPos();
|
||||
(void)disk_block_index->GetBlockTime();
|
||||
(void)disk_block_index->GetBlockTimeMax();
|
||||
(void)disk_block_index->GetMedianTimePast();
|
||||
(void)disk_block_index->GetUndoPos();
|
||||
(void)disk_block_index->HaveTxsDownloaded();
|
||||
(void)disk_block_index->IsValid();
|
||||
(void)disk_block_index->ToString();
|
||||
|
||||
const CBlockHeader block_header = disk_block_index->GetBlockHeader();
|
||||
(void)CDiskBlockIndex{*disk_block_index};
|
||||
(void)disk_block_index->BuildSkip();
|
||||
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
const BlockStatus block_status = fuzzed_data_provider.PickValueInArray({
|
||||
BlockStatus::BLOCK_VALID_UNKNOWN,
|
||||
BlockStatus::BLOCK_VALID_RESERVED,
|
||||
BlockStatus::BLOCK_VALID_TREE,
|
||||
BlockStatus::BLOCK_VALID_TRANSACTIONS,
|
||||
BlockStatus::BLOCK_VALID_CHAIN,
|
||||
BlockStatus::BLOCK_VALID_SCRIPTS,
|
||||
BlockStatus::BLOCK_VALID_MASK,
|
||||
BlockStatus::BLOCK_HAVE_DATA,
|
||||
BlockStatus::BLOCK_HAVE_UNDO,
|
||||
BlockStatus::BLOCK_HAVE_MASK,
|
||||
BlockStatus::BLOCK_FAILED_VALID,
|
||||
BlockStatus::BLOCK_FAILED_CHILD,
|
||||
BlockStatus::BLOCK_FAILED_MASK,
|
||||
BlockStatus::BLOCK_CONFLICT_CHAINLOCK
|
||||
});
|
||||
if (block_status & ~BLOCK_VALID_MASK) {
|
||||
continue;
|
||||
}
|
||||
(void)disk_block_index->RaiseValidity(block_status);
|
||||
}
|
||||
|
||||
CBlockIndex block_index{block_header};
|
||||
block_index.phashBlock = &zero;
|
||||
(void)block_index.GetBlockHash();
|
||||
(void)block_index.ToString();
|
||||
}
|
162
src/test/fuzz/connman.cpp
Normal file
162
src/test/fuzz/connman.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <chainparamsbase.h>
|
||||
#include <net.h>
|
||||
#include <netaddress.h>
|
||||
#include <protocol.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
void initialize()
|
||||
{
|
||||
InitializeFuzzingContext();
|
||||
}
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
|
||||
CAddress random_address;
|
||||
CNetAddr random_netaddr;
|
||||
CNode random_node = ConsumeNode(fuzzed_data_provider);
|
||||
CService random_service;
|
||||
CSubNet random_subnet;
|
||||
std::string random_string;
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 30)) {
|
||||
case 0:
|
||||
random_address = ConsumeAddress(fuzzed_data_provider);
|
||||
break;
|
||||
case 1:
|
||||
random_netaddr = ConsumeNetAddr(fuzzed_data_provider);
|
||||
break;
|
||||
case 2:
|
||||
random_service = ConsumeService(fuzzed_data_provider);
|
||||
break;
|
||||
case 3:
|
||||
random_subnet = ConsumeSubNet(fuzzed_data_provider);
|
||||
break;
|
||||
case 4:
|
||||
random_string = fuzzed_data_provider.ConsumeRandomLengthString(64);
|
||||
break;
|
||||
case 5: {
|
||||
std::vector<CAddress> addresses;
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
addresses.push_back(ConsumeAddress(fuzzed_data_provider));
|
||||
}
|
||||
// Limit nTimePenalty to int32_t to avoid signed integer overflow
|
||||
(void)connman.AddNewAddresses(addresses, ConsumeAddress(fuzzed_data_provider), fuzzed_data_provider.ConsumeIntegral<int32_t>());
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
connman.AddNode(random_string);
|
||||
break;
|
||||
case 7:
|
||||
connman.CheckIncomingNonce(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||
break;
|
||||
case 8:
|
||||
connman.DisconnectNode(fuzzed_data_provider.ConsumeIntegral<NodeId>());
|
||||
break;
|
||||
case 9:
|
||||
connman.DisconnectNode(random_netaddr);
|
||||
break;
|
||||
case 10:
|
||||
connman.DisconnectNode(random_string);
|
||||
break;
|
||||
case 11:
|
||||
connman.DisconnectNode(random_subnet);
|
||||
break;
|
||||
case 12:
|
||||
connman.ForEachNode([](auto) {});
|
||||
break;
|
||||
case 13:
|
||||
connman.ForEachNodeThen([](auto) {}, []() {});
|
||||
break;
|
||||
case 14:
|
||||
(void)connman.ForNode(fuzzed_data_provider.ConsumeIntegral<NodeId>(), [&](auto) { return fuzzed_data_provider.ConsumeBool(); });
|
||||
break;
|
||||
case 15:
|
||||
(void)connman.GetAddresses();
|
||||
break;
|
||||
case 16: {
|
||||
(void)connman.GetAddresses();
|
||||
break;
|
||||
}
|
||||
case 17:
|
||||
(void)connman.GetDeterministicRandomizer(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||
break;
|
||||
case 18:
|
||||
(void)connman.GetNodeCount(fuzzed_data_provider.PickValueInArray({CConnman::CONNECTIONS_NONE, CConnman::CONNECTIONS_IN, CConnman::CONNECTIONS_OUT, CConnman::CONNECTIONS_ALL}));
|
||||
break;
|
||||
case 19:
|
||||
connman.MarkAddressGood(random_address);
|
||||
break;
|
||||
case 20:
|
||||
(void)connman.OutboundTargetReached(fuzzed_data_provider.ConsumeBool());
|
||||
break;
|
||||
case 21:
|
||||
// Limit now to int32_t to avoid signed integer overflow
|
||||
(void)connman.PoissonNextSendInbound(fuzzed_data_provider.ConsumeIntegral<int32_t>(), fuzzed_data_provider.ConsumeIntegral<int>());
|
||||
break;
|
||||
case 22: {
|
||||
CSerializedNetMsg serialized_net_msg;
|
||||
serialized_net_msg.command = fuzzed_data_provider.ConsumeRandomLengthString(CMessageHeader::COMMAND_SIZE);
|
||||
serialized_net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
connman.PushMessage(&random_node, std::move(serialized_net_msg));
|
||||
break;
|
||||
}
|
||||
case 23:
|
||||
connman.RemoveAddedNode(random_string);
|
||||
break;
|
||||
case 24: {
|
||||
const std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
|
||||
if (SanityCheckASMap(asmap)) {
|
||||
connman.SetAsmap(asmap);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 25:
|
||||
connman.SetBestHeight(fuzzed_data_provider.ConsumeIntegral<int>());
|
||||
break;
|
||||
case 26:
|
||||
connman.SetMaxOutboundTarget(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||
break;
|
||||
case 27:
|
||||
connman.SetMaxOutboundTimeframe(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||
break;
|
||||
case 28:
|
||||
connman.SetNetworkActive(fuzzed_data_provider.ConsumeBool());
|
||||
break;
|
||||
case 29:
|
||||
connman.SetServices(random_service, static_cast<ServiceFlags>(fuzzed_data_provider.ConsumeIntegral<uint64_t>()));
|
||||
break;
|
||||
case 30:
|
||||
connman.SetTryNewOutboundPeer(fuzzed_data_provider.ConsumeBool());
|
||||
break;
|
||||
}
|
||||
}
|
||||
(void)connman.GetAddedNodeInfo();
|
||||
(void)connman.GetBestHeight();
|
||||
(void)connman.GetExtraOutboundCount();
|
||||
(void)connman.GetLocalServices();
|
||||
(void)connman.GetMaxOutboundTarget();
|
||||
(void)connman.GetMaxOutboundTimeframe();
|
||||
(void)connman.GetMaxOutboundTimeLeftInCycle();
|
||||
(void)connman.GetNetworkActive();
|
||||
std::vector<CNodeStats> stats;
|
||||
connman.GetNodeStats(stats);
|
||||
(void)connman.GetOutboundTargetBytesLeft();
|
||||
(void)connman.GetReceiveFloodSize();
|
||||
(void)connman.GetTotalBytesRecv();
|
||||
(void)connman.GetTotalBytesSent();
|
||||
(void)connman.GetTryNewOutboundPeer();
|
||||
(void)connman.GetUseAddrmanOutgoing();
|
||||
}
|
30
src/test/fuzz/crypto_aes256.cpp
Normal file
30
src/test/fuzz/crypto_aes256.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <crypto/aes.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
const std::vector<uint8_t> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES256_KEYSIZE);
|
||||
|
||||
AES256Encrypt encrypt{key.data()};
|
||||
AES256Decrypt decrypt{key.data()};
|
||||
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
const std::vector<uint8_t> plaintext = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES_BLOCKSIZE);
|
||||
std::vector<uint8_t> ciphertext(AES_BLOCKSIZE);
|
||||
encrypt.Encrypt(ciphertext.data(), plaintext.data());
|
||||
std::vector<uint8_t> decrypted_plaintext(AES_BLOCKSIZE);
|
||||
decrypt.Decrypt(decrypted_plaintext.data(), ciphertext.data());
|
||||
assert(decrypted_plaintext == plaintext);
|
||||
}
|
||||
}
|
34
src/test/fuzz/crypto_aes256cbc.cpp
Normal file
34
src/test/fuzz/crypto_aes256cbc.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <crypto/aes.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
const std::vector<uint8_t> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES256_KEYSIZE);
|
||||
const std::vector<uint8_t> iv = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES_BLOCKSIZE);
|
||||
const bool pad = fuzzed_data_provider.ConsumeBool();
|
||||
|
||||
AES256CBCEncrypt encrypt{key.data(), iv.data(), pad};
|
||||
AES256CBCDecrypt decrypt{key.data(), iv.data(), pad};
|
||||
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
const std::vector<uint8_t> plaintext = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
std::vector<uint8_t> ciphertext(plaintext.size() + AES_BLOCKSIZE);
|
||||
const int encrypt_ret = encrypt.Encrypt(plaintext.data(), plaintext.size(), ciphertext.data());
|
||||
ciphertext.resize(encrypt_ret);
|
||||
std::vector<uint8_t> decrypted_plaintext(ciphertext.size());
|
||||
const int decrypt_ret = decrypt.Decrypt(ciphertext.data(), ciphertext.size(), decrypted_plaintext.data());
|
||||
decrypted_plaintext.resize(decrypt_ret);
|
||||
assert(decrypted_plaintext == plaintext || (!pad && plaintext.size() % AES_BLOCKSIZE != 0 && encrypt_ret == 0 && decrypt_ret == 0));
|
||||
}
|
||||
}
|
50
src/test/fuzz/crypto_chacha20.cpp
Normal file
50
src/test/fuzz/crypto_chacha20.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <crypto/chacha20.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
|
||||
ChaCha20 chacha20;
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
const std::vector<unsigned char> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(16, 32));
|
||||
chacha20 = ChaCha20{key.data(), key.size()};
|
||||
}
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange(0, 4)) {
|
||||
case 0: {
|
||||
const std::vector<unsigned char> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(16, 32));
|
||||
chacha20.SetKey(key.data(), key.size());
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
chacha20.SetIV(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
chacha20.Seek(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
|
||||
chacha20.Keystream(output.data(), output.size());
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
|
||||
const std::vector<uint8_t> input = ConsumeFixedLengthByteVector(fuzzed_data_provider, output.size());
|
||||
chacha20.Crypt(input.data(), output.data(), input.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
72
src/test/fuzz/crypto_chacha20_poly1305_aead.cpp
Normal file
72
src/test/fuzz/crypto_chacha20_poly1305_aead.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <crypto/chacha_poly_aead.h>
|
||||
#include <crypto/poly1305.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
|
||||
const std::vector<uint8_t> k1 = ConsumeFixedLengthByteVector(fuzzed_data_provider, CHACHA20_POLY1305_AEAD_KEY_LEN);
|
||||
const std::vector<uint8_t> k2 = ConsumeFixedLengthByteVector(fuzzed_data_provider, CHACHA20_POLY1305_AEAD_KEY_LEN);
|
||||
|
||||
ChaCha20Poly1305AEAD aead(k1.data(), k1.size(), k2.data(), k2.size());
|
||||
uint64_t seqnr_payload = 0;
|
||||
uint64_t seqnr_aad = 0;
|
||||
int aad_pos = 0;
|
||||
size_t buffer_size = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096);
|
||||
std::vector<uint8_t> in(buffer_size + CHACHA20_POLY1305_AEAD_AAD_LEN + POLY1305_TAGLEN, 0);
|
||||
std::vector<uint8_t> out(buffer_size + CHACHA20_POLY1305_AEAD_AAD_LEN + POLY1305_TAGLEN, 0);
|
||||
bool is_encrypt = fuzzed_data_provider.ConsumeBool();
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 6)) {
|
||||
case 0: {
|
||||
buffer_size = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(64, 4096);
|
||||
in = std::vector<uint8_t>(buffer_size + CHACHA20_POLY1305_AEAD_AAD_LEN + POLY1305_TAGLEN, 0);
|
||||
out = std::vector<uint8_t>(buffer_size + CHACHA20_POLY1305_AEAD_AAD_LEN + POLY1305_TAGLEN, 0);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
(void)aead.Crypt(seqnr_payload, seqnr_aad, aad_pos, out.data(), out.size(), in.data(), buffer_size, is_encrypt);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
uint32_t len = 0;
|
||||
const bool ok = aead.GetLength(&len, seqnr_aad, aad_pos, in.data());
|
||||
assert(ok);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
seqnr_payload += 1;
|
||||
aad_pos += CHACHA20_POLY1305_AEAD_AAD_LEN;
|
||||
if (aad_pos + CHACHA20_POLY1305_AEAD_AAD_LEN > CHACHA20_ROUND_OUTPUT) {
|
||||
aad_pos = 0;
|
||||
seqnr_aad += 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
seqnr_payload = fuzzed_data_provider.ConsumeIntegral<int>();
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
seqnr_aad = fuzzed_data_provider.ConsumeIntegral<int>();
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
is_encrypt = fuzzed_data_provider.ConsumeBool();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
src/test/fuzz/crypto_hkdf_hmac_sha256_l32.cpp
Normal file
25
src/test/fuzz/crypto_hkdf_hmac_sha256_l32.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <crypto/hkdf_sha256_32.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
|
||||
const std::vector<uint8_t> initial_key_material = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
|
||||
CHKDF_HMAC_SHA256_L32 hkdf_hmac_sha256_l32(initial_key_material.data(), initial_key_material.size(), fuzzed_data_provider.ConsumeRandomLengthString(1024));
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
std::vector<uint8_t> out(32);
|
||||
hkdf_hmac_sha256_l32.Expand32(fuzzed_data_provider.ConsumeRandomLengthString(128), out.data());
|
||||
}
|
||||
}
|
22
src/test/fuzz/crypto_poly1305.cpp
Normal file
22
src/test/fuzz/crypto_poly1305.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <crypto/poly1305.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
|
||||
const std::vector<uint8_t> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, POLY1305_KEYLEN);
|
||||
const std::vector<uint8_t> in = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
|
||||
std::vector<uint8_t> tag_out(POLY1305_TAGLEN);
|
||||
poly1305_auth(tag_out.data(), in.data(), in.size(), key.data());
|
||||
}
|
22
src/test/fuzz/fees.cpp
Normal file
22
src/test/fuzz/fees.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <amount.h>
|
||||
#include <optional.h>
|
||||
#include <policy/fees.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <util/fees.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
const FeeReason fee_reason = fuzzed_data_provider.PickValueInArray({FeeReason::NONE, FeeReason::HALF_ESTIMATE, FeeReason::FULL_ESTIMATE, FeeReason::DOUBLE_ESTIMATE, FeeReason::CONSERVATIVE, FeeReason::MEMPOOL_MIN, FeeReason::PAYTXFEE, FeeReason::FALLBACK, FeeReason::REQUIRED});
|
||||
(void)StringForFeeReason(fee_reason);
|
||||
}
|
@ -24,8 +24,8 @@
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <time.h>
|
||||
#include <uint256.h>
|
||||
#include <util/check.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
@ -34,6 +34,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <limits>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
@ -262,8 +263,12 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
try {
|
||||
const uint64_t deserialized_u64 = ReadCompactSize(stream);
|
||||
assert(u64 == deserialized_u64 && stream.empty());
|
||||
}
|
||||
catch (const std::ios_base::failure&) {
|
||||
} catch (const std::ios_base::failure&) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
CHECK_NONFATAL(b);
|
||||
} catch (const NonFatalCheckError&) {
|
||||
}
|
||||
}
|
||||
|
26
src/test/fuzz/kitchen_sink.cpp
Normal file
26
src/test/fuzz/kitchen_sink.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <rpc/util.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <util/error.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
|
||||
// fuzzed but a.) don't belong in any existing fuzzing harness file, and
|
||||
// b.) are not important enough to warrant their own fuzzing harness file.
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
const TransactionError transaction_error = fuzzed_data_provider.PickValueInArray<TransactionError>({TransactionError::OK, TransactionError::MISSING_INPUTS, TransactionError::ALREADY_IN_CHAIN, TransactionError::P2P_DISABLED, TransactionError::MEMPOOL_REJECTED, TransactionError::MEMPOOL_ERROR, TransactionError::INVALID_PSBT, TransactionError::PSBT_MISMATCH, TransactionError::SIGHASH_MISMATCH, TransactionError::MAX_FEE_EXCEEDED});
|
||||
(void)JSONRPCTransactionError(transaction_error);
|
||||
(void)RPCErrorFromTransactionError(transaction_error);
|
||||
(void)TransactionErrorString(transaction_error);
|
||||
}
|
163
src/test/fuzz/net.cpp
Normal file
163
src/test/fuzz/net.cpp
Normal file
@ -0,0 +1,163 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <chainparamsbase.h>
|
||||
#include <net.h>
|
||||
#include <net_permissions.h>
|
||||
#include <netaddress.h>
|
||||
#include <optional.h>
|
||||
#include <protocol.h>
|
||||
#include <random.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void initialize()
|
||||
{
|
||||
static const BasicTestingSetup basic_testing_setup;
|
||||
}
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
const std::optional<CAddress> address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
|
||||
if (!address) {
|
||||
return;
|
||||
}
|
||||
const std::optional<CAddress> address_bind = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
|
||||
if (!address_bind) {
|
||||
return;
|
||||
}
|
||||
|
||||
CNode node{fuzzed_data_provider.ConsumeIntegral<NodeId>(),
|
||||
static_cast<ServiceFlags>(fuzzed_data_provider.ConsumeIntegral<uint64_t>()),
|
||||
fuzzed_data_provider.ConsumeIntegral<int>(),
|
||||
INVALID_SOCKET,
|
||||
*address,
|
||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||
*address_bind,
|
||||
fuzzed_data_provider.ConsumeRandomLengthString(32),
|
||||
fuzzed_data_provider.ConsumeBool(),
|
||||
fuzzed_data_provider.ConsumeBool()
|
||||
};
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 12)) {
|
||||
case 0: {
|
||||
CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
|
||||
node.CloseSocketDisconnect(&connman);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
node.MaybeSetAddrName(fuzzed_data_provider.ConsumeRandomLengthString(32));
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
node.SetSendVersion(fuzzed_data_provider.ConsumeIntegral<int>());
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
const std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
|
||||
if (!SanityCheckASMap(asmap)) {
|
||||
break;
|
||||
}
|
||||
CNodeStats stats;
|
||||
node.copyStats(stats, asmap);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
node.SetRecvVersion(fuzzed_data_provider.ConsumeIntegral<int>());
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
const CNode* add_ref_node = node.AddRef();
|
||||
assert(add_ref_node == &node);
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
if (node.GetRefCount() > 0) {
|
||||
node.Release();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
// if (node.m_addr_known == nullptr) {
|
||||
// break;
|
||||
// }
|
||||
const std::optional<CAddress> addr_opt = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
|
||||
if (!addr_opt) {
|
||||
break;
|
||||
}
|
||||
node.AddAddressKnown(*addr_opt);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
// if (node.m_addr_known == nullptr) {
|
||||
// break;
|
||||
// }
|
||||
const std::optional<CAddress> addr_opt = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
|
||||
if (!addr_opt) {
|
||||
break;
|
||||
}
|
||||
FastRandomContext fast_random_context{ConsumeUInt256(fuzzed_data_provider)};
|
||||
node.PushAddress(*addr_opt, fast_random_context);
|
||||
break;
|
||||
}
|
||||
case 9: {
|
||||
const std::optional<CInv> inv_opt = ConsumeDeserializable<CInv>(fuzzed_data_provider);
|
||||
if (!inv_opt) {
|
||||
break;
|
||||
}
|
||||
// node.AddKnownTx(inv_opt->hash);
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
const std::optional<CInv> inv_opt = ConsumeDeserializable<CInv>(fuzzed_data_provider);
|
||||
if (!inv_opt) {
|
||||
break;
|
||||
}
|
||||
node.PushInventory(*inv_opt);
|
||||
break;
|
||||
}
|
||||
case 11: {
|
||||
const std::optional<CService> service_opt = ConsumeDeserializable<CService>(fuzzed_data_provider);
|
||||
if (!service_opt) {
|
||||
break;
|
||||
}
|
||||
node.SetAddrLocal(*service_opt);
|
||||
break;
|
||||
}
|
||||
case 12: {
|
||||
const std::vector<uint8_t> b = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
bool complete;
|
||||
node.ReceiveMsgBytes((const char*)b.data(), b.size(), complete);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(void)node.GetAddrLocal();
|
||||
(void)node.GetAddrName();
|
||||
(void)node.GetId();
|
||||
(void)node.GetLocalNonce();
|
||||
(void)node.GetLocalServices();
|
||||
(void)node.GetMyStartingHeight();
|
||||
(void)node.GetRecvVersion();
|
||||
const int ref_count = node.GetRefCount();
|
||||
assert(ref_count >= 0);
|
||||
(void)node.GetSendVersion();
|
||||
(void)node.IsAddrRelayPeer();
|
||||
|
||||
const NetPermissionFlags net_permission_flags = fuzzed_data_provider.ConsumeBool() ?
|
||||
fuzzed_data_provider.PickValueInArray<NetPermissionFlags>({NetPermissionFlags::PF_NONE, NetPermissionFlags::PF_BLOOMFILTER, NetPermissionFlags::PF_RELAY, NetPermissionFlags::PF_FORCERELAY, NetPermissionFlags::PF_NOBAN, NetPermissionFlags::PF_MEMPOOL, NetPermissionFlags::PF_ISIMPLICIT, NetPermissionFlags::PF_ALL}) :
|
||||
static_cast<NetPermissionFlags>(fuzzed_data_provider.ConsumeIntegral<uint32_t>());
|
||||
(void)node.HasPermission(net_permission_flags);
|
||||
}
|
@ -2,12 +2,22 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <util/bip32.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
const std::string keypath_str(buffer.begin(), buffer.end());
|
||||
std::vector<uint32_t> keypath;
|
||||
(void)ParseHDKeypath(keypath_str, keypath);
|
||||
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
const std::vector<uint32_t> random_keypath = ConsumeRandomLengthIntegralVector<uint32_t>(fuzzed_data_provider);
|
||||
(void)FormatHDKeypath(random_keypath);
|
||||
(void)WriteHDKeypath(random_keypath);
|
||||
}
|
||||
|
69
src/test/fuzz/policy_estimator.cpp
Normal file
69
src/test/fuzz/policy_estimator.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <optional.h>
|
||||
#include <policy/fees.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <txmempool.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
CBlockPolicyEstimator block_policy_estimator;
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 3)) {
|
||||
case 0: {
|
||||
const Optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
if (!mtx) {
|
||||
break;
|
||||
}
|
||||
const CTransaction tx{*mtx};
|
||||
block_policy_estimator.processTransaction(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx), fuzzed_data_provider.ConsumeBool());
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
(void)block_policy_estimator.removeTx(tx.GetHash(), /* inBlock */ fuzzed_data_provider.ConsumeBool());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
std::vector<CTxMemPoolEntry> mempool_entries;
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
const Optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
if (!mtx) {
|
||||
break;
|
||||
}
|
||||
const CTransaction tx{*mtx};
|
||||
mempool_entries.push_back(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
|
||||
}
|
||||
std::vector<const CTxMemPoolEntry*> ptrs;
|
||||
ptrs.reserve(mempool_entries.size());
|
||||
for (const CTxMemPoolEntry& mempool_entry : mempool_entries) {
|
||||
ptrs.push_back(&mempool_entry);
|
||||
}
|
||||
block_policy_estimator.processBlock(fuzzed_data_provider.ConsumeIntegral<unsigned int>(), ptrs);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
(void)block_policy_estimator.removeTx(ConsumeUInt256(fuzzed_data_provider), /* inBlock */ fuzzed_data_provider.ConsumeBool());
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
block_policy_estimator.FlushUnconfirmed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
(void)block_policy_estimator.estimateFee(fuzzed_data_provider.ConsumeIntegral<int>());
|
||||
EstimationResult result;
|
||||
(void)block_policy_estimator.estimateRawFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeFloatingPoint<double>(), fuzzed_data_provider.PickValueInArray({FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}), fuzzed_data_provider.ConsumeBool() ? &result : nullptr);
|
||||
FeeCalculation fee_calculation;
|
||||
(void)block_policy_estimator.estimateSmartFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeBool() ? &fee_calculation : nullptr, fuzzed_data_provider.ConsumeBool());
|
||||
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray({FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}));
|
||||
}
|
||||
}
|
34
src/test/fuzz/primitives_transaction.cpp
Normal file
34
src/test/fuzz/primitives_transaction.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <optional.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
const CScript script = ConsumeScript(fuzzed_data_provider);
|
||||
const Optional<COutPoint> out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
|
||||
if (out_point) {
|
||||
const CTxIn tx_in{*out_point, script, fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
|
||||
(void)tx_in;
|
||||
}
|
||||
const CTxOut tx_out_1{ConsumeMoney(fuzzed_data_provider), script};
|
||||
const CTxOut tx_out_2{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)};
|
||||
assert((tx_out_1 == tx_out_2) != (tx_out_1 != tx_out_2));
|
||||
const Optional<CMutableTransaction> mutable_tx_1 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const Optional<CMutableTransaction> mutable_tx_2 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
if (mutable_tx_1 && mutable_tx_2) {
|
||||
const CTransaction tx_1{*mutable_tx_1};
|
||||
const CTransaction tx_2{*mutable_tx_2};
|
||||
assert((tx_1 == tx_2) != (tx_1 != tx_2));
|
||||
}
|
||||
}
|
32
src/test/fuzz/protocol.cpp
Normal file
32
src/test/fuzz/protocol.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <optional.h>
|
||||
#include <protocol.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
const Optional<CInv> inv = ConsumeDeserializable<CInv>(fuzzed_data_provider);
|
||||
if (!inv) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
(void)inv->GetCommand();
|
||||
} catch (const std::out_of_range&) {
|
||||
}
|
||||
(void)inv->ToString();
|
||||
const Optional<CInv> another_inv = ConsumeDeserializable<CInv>(fuzzed_data_provider);
|
||||
if (!another_inv) {
|
||||
return;
|
||||
}
|
||||
(void)(*inv < *another_inv);
|
||||
}
|
38
src/test/fuzz/secp256k1_ec_seckey_import_export_der.cpp
Normal file
38
src/test/fuzz/secp256k1_ec_seckey_import_export_der.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <key.h>
|
||||
#include <secp256k1.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
int ec_seckey_import_der(const secp256k1_context* ctx, unsigned char* out32, const unsigned char* seckey, size_t seckeylen);
|
||||
int ec_seckey_export_der(const secp256k1_context* ctx, unsigned char* seckey, size_t* seckeylen, const unsigned char* key32, bool compressed);
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
secp256k1_context* secp256k1_context_sign = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
|
||||
{
|
||||
std::vector<uint8_t> out32(32);
|
||||
(void)ec_seckey_import_der(secp256k1_context_sign, out32.data(), ConsumeFixedLengthByteVector(fuzzed_data_provider, CKey::SIZE).data(), CKey::SIZE);
|
||||
}
|
||||
{
|
||||
std::vector<uint8_t> seckey(CKey::SIZE);
|
||||
const std::vector<uint8_t> key32 = ConsumeFixedLengthByteVector(fuzzed_data_provider, 32);
|
||||
size_t seckeylen = CKey::SIZE;
|
||||
const bool compressed = fuzzed_data_provider.ConsumeBool();
|
||||
const bool exported = ec_seckey_export_der(secp256k1_context_sign, seckey.data(), &seckeylen, key32.data(), compressed);
|
||||
if (exported) {
|
||||
std::vector<uint8_t> out32(32);
|
||||
const bool imported = ec_seckey_import_der(secp256k1_context_sign, out32.data(), seckey.data(), seckey.size()) == 1;
|
||||
assert(imported && key32 == out32);
|
||||
}
|
||||
}
|
||||
secp256k1_context_destroy(secp256k1_context_sign);
|
||||
}
|
33
src/test/fuzz/secp256k1_ecdsa_signature_parse_der_lax.cpp
Normal file
33
src/test/fuzz/secp256k1_ecdsa_signature_parse_der_lax.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <key.h>
|
||||
#include <secp256k1.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
bool SigHasLowR(const secp256k1_ecdsa_signature* sig);
|
||||
int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char* input, size_t inputlen);
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
const std::vector<uint8_t> signature_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
if (signature_bytes.data() == nullptr) {
|
||||
return;
|
||||
}
|
||||
secp256k1_context* secp256k1_context_verify = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY);
|
||||
secp256k1_ecdsa_signature sig_der_lax;
|
||||
const bool parsed_der_lax = ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig_der_lax, signature_bytes.data(), signature_bytes.size()) == 1;
|
||||
if (parsed_der_lax) {
|
||||
ECC_Start();
|
||||
(void)SigHasLowR(&sig_der_lax);
|
||||
ECC_Stop();
|
||||
}
|
||||
secp256k1_context_destroy(secp256k1_context_verify);
|
||||
}
|
@ -110,4 +110,8 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
assert(data_stream.empty());
|
||||
assert(deserialized_string == random_string_1);
|
||||
}
|
||||
{
|
||||
int64_t amount_out;
|
||||
(void)ParseFixedPoint(random_string_1, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 1024), &amount_out);
|
||||
}
|
||||
}
|
||||
|
123
src/test/fuzz/system.cpp
Normal file
123
src/test/fuzz/system.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <util/system.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
std::string GetArgumentName(const std::string& name)
|
||||
{
|
||||
size_t idx = name.find('=');
|
||||
if (idx == std::string::npos) {
|
||||
idx = name.size();
|
||||
}
|
||||
return name.substr(0, idx);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
ArgsManager args_manager{};
|
||||
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
SetupHelpOptions(args_manager);
|
||||
}
|
||||
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 7)) {
|
||||
case 0: {
|
||||
args_manager.SelectConfigNetwork(fuzzed_data_provider.ConsumeRandomLengthString(16));
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
args_manager.SoftSetArg(fuzzed_data_provider.ConsumeRandomLengthString(16), fuzzed_data_provider.ConsumeRandomLengthString(16));
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
args_manager.ForceSetArg(fuzzed_data_provider.ConsumeRandomLengthString(16), fuzzed_data_provider.ConsumeRandomLengthString(16));
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
args_manager.SoftSetBoolArg(fuzzed_data_provider.ConsumeRandomLengthString(16), fuzzed_data_provider.ConsumeBool());
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
const OptionsCategory options_category = fuzzed_data_provider.PickValueInArray<OptionsCategory>({OptionsCategory::OPTIONS, OptionsCategory::CONNECTION, OptionsCategory::WALLET, OptionsCategory::WALLET_DEBUG_TEST, OptionsCategory::ZMQ, OptionsCategory::DEBUG_TEST, OptionsCategory::CHAINPARAMS, OptionsCategory::NODE_RELAY, OptionsCategory::BLOCK_CREATION, OptionsCategory::RPC, OptionsCategory::GUI, OptionsCategory::COMMANDS, OptionsCategory::REGISTER_COMMANDS, OptionsCategory::HIDDEN});
|
||||
// Avoid hitting:
|
||||
// util/system.cpp:425: void ArgsManager::AddArg(const std::string &, const std::string &, unsigned int, const OptionsCategory &): Assertion `ret.second' failed.
|
||||
const std::string argument_name = GetArgumentName(fuzzed_data_provider.ConsumeRandomLengthString(16));
|
||||
if (args_manager.GetArgFlags(argument_name) != nullopt) {
|
||||
break;
|
||||
}
|
||||
args_manager.AddArg(argument_name, fuzzed_data_provider.ConsumeRandomLengthString(16), fuzzed_data_provider.ConsumeIntegral<unsigned int>(), options_category);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
// Avoid hitting:
|
||||
// util/system.cpp:425: void ArgsManager::AddArg(const std::string &, const std::string &, unsigned int, const OptionsCategory &): Assertion `ret.second' failed.
|
||||
const std::vector<std::string> names = ConsumeRandomLengthStringVector(fuzzed_data_provider);
|
||||
std::vector<std::string> hidden_arguments;
|
||||
for (const std::string& name : names) {
|
||||
const std::string hidden_argument = GetArgumentName(name);
|
||||
if (args_manager.GetArgFlags(hidden_argument) != nullopt) {
|
||||
continue;
|
||||
}
|
||||
if (std::find(hidden_arguments.begin(), hidden_arguments.end(), hidden_argument) != hidden_arguments.end()) {
|
||||
continue;
|
||||
}
|
||||
hidden_arguments.push_back(hidden_argument);
|
||||
}
|
||||
args_manager.AddHiddenArgs(hidden_arguments);
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
args_manager.ClearArgs();
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
const std::vector<std::string> random_arguments = ConsumeRandomLengthStringVector(fuzzed_data_provider);
|
||||
std::vector<const char*> argv;
|
||||
argv.resize(random_arguments.size());
|
||||
for (const std::string& random_argument : random_arguments) {
|
||||
argv.push_back(random_argument.c_str());
|
||||
}
|
||||
try {
|
||||
std::string error;
|
||||
(void)args_manager.ParseParameters(argv.size(), argv.data(), error);
|
||||
} catch (const std::logic_error&) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::string s1 = fuzzed_data_provider.ConsumeRandomLengthString(16);
|
||||
const std::string s2 = fuzzed_data_provider.ConsumeRandomLengthString(16);
|
||||
const int64_t i64 = fuzzed_data_provider.ConsumeIntegral<int64_t>();
|
||||
const bool b = fuzzed_data_provider.ConsumeBool();
|
||||
|
||||
(void)args_manager.GetArg(s1, i64);
|
||||
(void)args_manager.GetArg(s1, s2);
|
||||
(void)args_manager.GetArgFlags(s1);
|
||||
(void)args_manager.GetArgs(s1);
|
||||
(void)args_manager.GetBoolArg(s1, b);
|
||||
try {
|
||||
(void)args_manager.GetChainName();
|
||||
} catch (const std::runtime_error&) {
|
||||
}
|
||||
(void)args_manager.GetHelpMessage();
|
||||
(void)args_manager.GetUnrecognizedSections();
|
||||
(void)args_manager.GetUnsuitableSectionOnlyArgs();
|
||||
(void)args_manager.IsArgNegated(s1);
|
||||
(void)args_manager.IsArgSet(s1);
|
||||
|
||||
(void)HelpRequested(args_manager);
|
||||
}
|
@ -10,16 +10,22 @@
|
||||
#include <attributes.h>
|
||||
#include <chainparamsbase.h>
|
||||
#include <coins.h>
|
||||
#include <consensus/consensus.h>
|
||||
#include <merkleblock.h>
|
||||
#include <net.h>
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
#include <optional.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <script/script.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <txmempool.h>
|
||||
#include <uint256.h>
|
||||
#include <util/time.h>
|
||||
#include <version.h>
|
||||
|
||||
#include <cstdint>
|
||||
@ -33,6 +39,16 @@
|
||||
return {s.begin(), s.end()};
|
||||
}
|
||||
|
||||
[[ nodiscard ]] inline std::vector<bool> ConsumeRandomLengthBitVector(FuzzedDataProvider& fuzzed_data_provider, const size_t max_length = 4096) noexcept
|
||||
{
|
||||
return BytesToBits(ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length));
|
||||
}
|
||||
|
||||
[[ nodiscard ]] inline CDataStream ConsumeDataStream(FuzzedDataProvider& fuzzed_data_provider, const size_t max_length = 4096) noexcept
|
||||
{
|
||||
return {ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length), SER_NETWORK, INIT_PROTO_VERSION};
|
||||
}
|
||||
|
||||
[[ nodiscard ]] inline std::vector<std::string> ConsumeRandomLengthStringVector(FuzzedDataProvider& fuzzed_data_provider, const size_t max_vector_size = 16, const size_t max_string_length = 16) noexcept
|
||||
{
|
||||
const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, max_vector_size);
|
||||
@ -78,6 +94,13 @@ template <typename T>
|
||||
return fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(0, MAX_MONEY);
|
||||
}
|
||||
|
||||
[[ nodiscard ]] inline int64_t ConsumeTime(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
static const int64_t time_min = ParseISO8601DateTime("1970-01-01T00:00:00Z");
|
||||
static const int64_t time_max = ParseISO8601DateTime("9999-12-31T23:59:59Z");
|
||||
return fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(time_min, time_max);
|
||||
}
|
||||
|
||||
[[ nodiscard ]] inline CScript ConsumeScript(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
const std::vector<uint8_t> b = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
@ -104,6 +127,22 @@ template <typename T>
|
||||
return UintToArith256(ConsumeUInt256(fuzzed_data_provider));
|
||||
}
|
||||
|
||||
[[ nodiscard ]] inline CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider& fuzzed_data_provider, const CTransaction& tx) noexcept
|
||||
{
|
||||
// Avoid:
|
||||
// policy/feerate.cpp:28:34: runtime error: signed integer overflow: 34873208148477500 * 1000 cannot be represented in type 'long'
|
||||
//
|
||||
// Reproduce using CFeeRate(348732081484775, 10).GetFeePerK()
|
||||
const CAmount fee = std::min<CAmount>(ConsumeMoney(fuzzed_data_provider), std::numeric_limits<CAmount>::max() / static_cast<CAmount>(100000));
|
||||
assert(MoneyRange(fee));
|
||||
const int64_t time = fuzzed_data_provider.ConsumeIntegral<int64_t>();
|
||||
const unsigned int entry_height = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
||||
const bool spends_coinbase = fuzzed_data_provider.ConsumeBool();
|
||||
const bool dip1_status = fuzzed_data_provider.ConsumeBool();
|
||||
const unsigned int sig_op_cost = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, MaxBlockSigOps(dip1_status));
|
||||
return CTxMemPoolEntry{MakeTransactionRef(tx), fee, time, entry_height, spends_coinbase, sig_op_cost, {}};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[ nodiscard ]] bool MultiplicationOverflow(const T i, const T j) noexcept
|
||||
{
|
||||
@ -190,6 +229,32 @@ CSubNet ConsumeSubNet(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
return {ConsumeNetAddr(fuzzed_data_provider), fuzzed_data_provider.ConsumeIntegral<uint8_t>()};
|
||||
}
|
||||
|
||||
CService ConsumeService(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
return {ConsumeNetAddr(fuzzed_data_provider), fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
|
||||
}
|
||||
|
||||
CAddress ConsumeAddress(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
return {ConsumeService(fuzzed_data_provider), static_cast<ServiceFlags>(fuzzed_data_provider.ConsumeIntegral<uint64_t>()), fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
|
||||
}
|
||||
|
||||
CNode ConsumeNode(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
const NodeId node_id = fuzzed_data_provider.ConsumeIntegral<NodeId>();
|
||||
const ServiceFlags local_services = static_cast<ServiceFlags>(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||
const int my_starting_height = fuzzed_data_provider.ConsumeIntegral<int>();
|
||||
const SOCKET socket = INVALID_SOCKET;
|
||||
const CAddress address = ConsumeAddress(fuzzed_data_provider);
|
||||
const uint64_t keyed_net_group = fuzzed_data_provider.ConsumeIntegral<uint64_t>();
|
||||
const uint64_t local_host_nonce = fuzzed_data_provider.ConsumeIntegral<uint64_t>();
|
||||
const CAddress addr_bind = ConsumeAddress(fuzzed_data_provider);
|
||||
const std::string addr_name = fuzzed_data_provider.ConsumeRandomLengthString(64);
|
||||
const bool inbound = fuzzed_data_provider.ConsumeBool();
|
||||
const bool block_relay_only = fuzzed_data_provider.ConsumeBool();
|
||||
return {node_id, local_services, my_starting_height, socket, address, keyed_net_group, local_host_nonce, addr_bind, addr_name, inbound, block_relay_only};
|
||||
}
|
||||
|
||||
void InitializeFuzzingContext(const std::string& chain_name = CBaseChainParams::REGTEST)
|
||||
{
|
||||
static const BasicTestingSetup basic_testing_setup{chain_name, {"-nodebuglogfile"}};
|
||||
|
Loading…
Reference in New Issue
Block a user