From c1f0d43047dc33f52199e427bd7d099e87cfd664 Mon Sep 17 00:00:00 2001 From: mj-xmr Date: Mon, 2 Nov 2020 14:27:51 +0100 Subject: [PATCH 01/12] Run Valgrind checks for any binary in a list --- utils/health/valgrind-tests.sh | 161 +++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 utils/health/valgrind-tests.sh diff --git a/utils/health/valgrind-tests.sh b/utils/health/valgrind-tests.sh new file mode 100755 index 000000000..9f5e7e7c0 --- /dev/null +++ b/utils/health/valgrind-tests.sh @@ -0,0 +1,161 @@ +#!/bin/bash -e + +# Copyright (c) 2014-2020, The Monero Project +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are +# permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other +# materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be +# used to endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# This script is able to run valgrind's callgrind, cachegrind and memcheck for a given set of executables. +# It expects ONE PARAMETER, which points to a file with paths to executables and their arguments, written line by line. + +if [ "$#" -ne 1 ]; then + echo "Please provide an argument, which points to a file with paths to executables and their arguments, written line by line. For example:" + echo "" + echo "ls -l -h" + echo "build/tests/unit_tests/unit_tests" + exit 1 +fi + +FILE_IN="$1" +DIR_OUT="build/valgrind-output" # Using build as the base output directory, as it's ignored in .gitignore + +function is_file_or_exit { + FILE="${1}" + if [ -f $FILE ]; then + echo "The input file $FILE exists. Can proceed." + else + echo "The input file $FILE doesn't exist." + exit 1 + fi + return 0 +} + +function is_tool_or_exit { + TOOL="${1}" + if $(hash ${TOOL}); then + echo "${TOOL} is installed. Can proceed." + else + echo "Please install ${TOOL} to continue." + exit 1 + fi + return 0 +} + +function get_tool_out_file_base { + EXE="${1}" + TOOL="${2}" + + EXE_NAME=$(basename $EXE) + local retval="${DIR_OUT}/${EXE_NAME}-${TOOL}" + echo "$retval" +} + +function get_tool_out_file { + EXE="${1}" + TOOL="${2}" + + FILE_OUT_BASE=$(get_tool_out_file_base ${EXE} ${TOOL}) + local retval="--${TOOL}-out-file=${FILE_OUT_BASE}.out" + echo "$retval" +} + +function run_valgrind_4_executable { + EXE="${1}" + ARGS="${2}" + TOOL="${3}" + EXTRA_OPTS="${4}" + FILE_OUT_TOOL="${5}" + FILE_OUT_BASE=$(get_tool_out_file_base ${EXE} ${TOOL}) + + echo "Runnig '${TOOL}' for '${EXE}' with args '${ARGS}'" + echo "EXTRA_OPTS = ${EXTRA_OPTS}" + echo "FILE_OUT_TOOL = ${FILE_OUT_TOOL}" + if ! valgrind --tool=${TOOL} ${FILE_OUT_TOOL} --log-file="${FILE_OUT_BASE}.log" ${EXTRA_OPTS} ${EXE} ${ARGS}; then + echo "FAILED in runnig ${TOOL} for ${EXE} !" + fi +} + +function run_valgrind_4_executable_callgrind { + EXE="${1}" + ARGS="${2}" + TOOL="callgrind" + EXTRA_OPTS="--dump-instr=yes --simulate-cache=yes --collect-jumps=yes" + FILE_OUT_TOOL=$(get_tool_out_file ${EXE} ${TOOL}) + + run_valgrind_4_executable ${EXE} "${ARGS}" ${TOOL} "${EXTRA_OPTS}" ${FILE_OUT_TOOL} +} + +function run_valgrind_4_executable_cachegrind { + EXE="${1}" + ARGS="${2}" + TOOL="cachegrind" + EXTRA_OPTS="" + FILE_OUT_TOOL=$(get_tool_out_file ${EXE} ${TOOL}) + + run_valgrind_4_executable ${EXE} "${ARGS}" ${TOOL} "${EXTRA_OPTS}" ${FILE_OUT_TOOL} +} + +function run_valgrind_4_executable_memcheck { + EXE="${1}" + ARGS="${2}" + TOOL="memcheck" + #EXTRA_OPTS="--leak-check=yes" # Minimalistic + EXTRA_OPTS="--leak-check=full --show-leak-kinds=all --track-origins=yes" + FILE_OUT_TOOL="" # memcheck has no special out file, only the log + + run_valgrind_4_executable ${EXE} "${ARGS}" ${TOOL} "${EXTRA_OPTS}" ${FILE_OUT_TOOL} +} + +function run_valgrind_4_executable_all { + EXE_ARGS_ARR=(${1}) + EXE=${EXE_ARGS_ARR[0]} # First element of the array + ARGS=${EXE_ARGS_ARR[@]:1} # Every next element + + #EXE="ls" # A quick check of the happy path + #EXE="nothere" # A quick check of error handling - no such executable + #EXE=/bin/false # A quick check of error handling - executable returned != 0 + + run_valgrind_4_executable_memcheck ${EXE} "${ARGS}" + run_valgrind_4_executable_cachegrind ${EXE} "${ARGS}" + run_valgrind_4_executable_callgrind ${EXE} "${ARGS}" +} + +is_tool_or_exit valgrind +is_file_or_exit "$FILE_IN" +echo "All OK." +echo "Will perform checks for the following executables and their arguments:" +while IFS= read -r line; do + echo "$line" +done < "$FILE_IN" + +mkdir -p "$DIR_OUT" +while IFS= read -r line; do + echo "$line" + run_valgrind_4_executable_all "$line" +done < "$FILE_IN" + +echo "Done. All data saved in ${DIR_OUT}" + From fea538fcda520085a0d1c008a78253cc25409f56 Mon Sep 17 00:00:00 2001 From: mj-xmr Date: Fri, 6 Nov 2020 17:45:32 +0100 Subject: [PATCH 02/12] Clang IWYU header checker script Run with utils/health/clang-include-what-you-use-run.sh --- utils/health/README.md | 4 + .../health/clang-include-what-you-use-run.sh | 75 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 utils/health/clang-include-what-you-use-run.sh diff --git a/utils/health/README.md b/utils/health/README.md index dea46280e..8fadd3908 100644 --- a/utils/health/README.md +++ b/utils/health/README.md @@ -15,6 +15,10 @@ On the first run, the script will complain about the missing ClangBuildAnalyzer `utils/health/clang-tidy-run.sh` Performs Lint checks on the source code and stores the result in the build directory. More information on the [home page](https://clang.llvm.org/extra/clang-tidy/). +##include-what-you-use +`utils/health/clang-include-what-you-use-run.sh` +Analyses the header file hierarchy and delivers hints on how to reduce their complexity. More information on the [home page](https://include-what-you-use.org/). + ##Valgrind checks `utils/health/valgrind-tests.sh` diff --git a/utils/health/clang-include-what-you-use-run.sh b/utils/health/clang-include-what-you-use-run.sh new file mode 100755 index 000000000..655a188bd --- /dev/null +++ b/utils/health/clang-include-what-you-use-run.sh @@ -0,0 +1,75 @@ +#!/bin/bash -e + +# Copyright (c) 2014-2020, The Monero Project +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are +# permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other +# materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be +# used to endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Include What You Use analyses the complexity of your header hierarchy and proposes optimisations. +# User documentation: +# https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md + +# Build variables +PROG="include-what-you-use" +PROG_SHORT="iwyu" +DIR_BUILD="build/clang-$PROG_SHORT" + +RESULT="$PROG_SHORT-result.txt" + +if hash "$PROG"; then + echo "Found: $PROG" +else + echo "Couldn't find: $PROG" + echo "Please run the below command to install $PROG:" + echo "sudo apt install $PROG_SHORT" + exit 1 +fi + +mkdir -p "$DIR_BUILD" && cd "$DIR_BUILD" +rm `find . -name "CMakeCache.txt"` || true + +UWYU_COMMAND="$PROG;-Xiwyu;any;-Xiwyu;iwyu;-Xiwyu;args" # Copy-pasted from the user docs. + +cmake ../.. \ +-DCMAKE_C_COMPILER=clang \ +-DCMAKE_CXX_COMPILER=clang++ \ +-DUSE_CCACHE=ON \ +-DCMAKE_C_INCLUDE_WHAT_YOU_USE="$UWYU_COMMAND" \ +-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="$UWYU_COMMAND" \ +-DBUILD_SHARED_LIBS=ON \ +-DBUILD_TESTS=ON + +make clean # Clean up to generate the full report +time make -k 2>&1 | tee "$RESULT" # Run the scan. -k means: ignore errors +#time make -k easylogging 2>&1 | tee $RESULT # Quick testing: build a single target +KPI=$(cat "$RESULT" | wc -l) +tar -cJvf "$RESULT.txz" "$RESULT" # Zip the result, because it's huge. +rm -v "$RESULT" + +echo "" +echo "Readable result stored in: $DIR_BUILD/$RESULT.gz" + +echo "$KPI" > "kpis.txt" From 1212e1791c37d5335a8d372f41018326b0d49102 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 6 Dec 2020 16:09:28 +0000 Subject: [PATCH 03/12] rpc: report target height as 0 when synced since it only makes sense when syncing, and it confuses people --- src/rpc/core_rpc_server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 9faab0460..bebf595c6 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -452,7 +452,7 @@ namespace cryptonote m_core.get_blockchain_top(res.height, top_hash); ++res.height; // turn top block height into blockchain height res.top_block_hash = string_tools::pod_to_hex(top_hash); - res.target_height = m_core.get_target_blockchain_height(); + res.target_height = m_p2p.get_payload_object().is_synchronized() ? 0 : m_core.get_target_blockchain_height(); store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(), res.difficulty, res.wide_difficulty, res.difficulty_top64); res.target = m_core.get_blockchain_storage().get_difficulty_target(); res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase @@ -2915,7 +2915,7 @@ namespace cryptonote crypto::hash top_hash; m_core.get_blockchain_top(res.height, top_hash); ++res.height; // turn top block height into blockchain height - res.target_height = m_core.get_target_blockchain_height(); + res.target_height = m_p2p.get_payload_object().is_synchronized() ? 0 : m_core.get_target_blockchain_height(); res.next_needed_pruning_seed = m_p2p.get_payload_object().get_next_needed_pruning_stripe().second; for (const auto &c: m_p2p.get_payload_object().get_connections()) From 2ec025d1a3d18ae3a44185afa34fa20fb205faf2 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 10 Dec 2020 17:56:35 +0000 Subject: [PATCH 04/12] simplewallet: don't complain about connecting to the daemon when offline --- src/simplewallet/simplewallet.cpp | 13 +++++++++---- src/wallet/wallet2.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 96389b109..dff02997f 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -4745,9 +4745,14 @@ bool simple_wallet::try_connect_to_daemon(bool silent, uint32_t* version) if (!m_wallet->check_connection(version)) { if (!silent) - fail_msg_writer() << tr("wallet failed to connect to daemon: ") << m_wallet->get_daemon_address() << ". " << - tr("Daemon either is not started or wrong port was passed. " - "Please make sure daemon is running or change the daemon address using the 'set_daemon' command."); + { + if (m_wallet->is_offline()) + fail_msg_writer() << tr("wallet failed to connect to daemon, because it is set to offline mode"); + else + fail_msg_writer() << tr("wallet failed to connect to daemon: ") << m_wallet->get_daemon_address() << ". " << + tr("Daemon either is not started or wrong port was passed. " + "Please make sure daemon is running or change the daemon address using the 'set_daemon' command."); + } return false; } if (!m_allow_mismatched_daemon_version && ((*version >> 16) != CORE_RPC_VERSION_MAJOR)) @@ -9278,7 +9283,7 @@ bool simple_wallet::run() refresh_main(0, ResetNone, true); - m_auto_refresh_enabled = m_wallet->auto_refresh(); + m_auto_refresh_enabled = !m_wallet->is_offline() && m_wallet->auto_refresh(); m_idle_thread = boost::thread([&]{wallet_idle_thread();}); message_writer(console_color_green, false) << "Background refresh thread started"; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index fed7d745c..c51c4ba48 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1546,6 +1546,7 @@ private: void finish_rescan_bc_keep_key_images(uint64_t transfer_height, const crypto::hash &hash); void enable_dns(bool enable) { m_use_dns = enable; } void set_offline(bool offline = true); + bool is_offline() const { return m_offline; } uint64_t credits() const { return m_rpc_payment_state.credits; } void credit_report(uint64_t &expected_spent, uint64_t &discrepancy) const { expected_spent = m_rpc_payment_state.expected_spent; discrepancy = m_rpc_payment_state.discrepancy; } From f17b506d3df988970304e31c9a02de82e940a5f4 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 10 Dec 2020 20:36:46 +0000 Subject: [PATCH 05/12] protocol: add calls to reserve where appropriate --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 9034ea5bf..dfd02957d 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -549,6 +549,7 @@ namespace cryptonote } std::vector have_tx; + have_tx.reserve(new_block.tx_hashes.size()); // Instead of requesting missing transactions by hash like BTC, // we do it by index (thanks to a suggestion from moneromooo) because @@ -557,6 +558,7 @@ namespace cryptonote // Also, remember to pepper some whitespace changes around to bother // moneromooo ... only because I <3 him. std::vector need_tx_indices; + need_tx_indices.reserve(new_block.tx_hashes.size()); transaction tx; crypto::hash tx_hash; @@ -829,6 +831,7 @@ namespace cryptonote } std::vector txids; + txids.reserve(b.tx_hashes.size()); NOTIFY_NEW_FLUFFY_BLOCK::request fluffy_response; fluffy_response.b.block = t_serializable_object_to_blob(b); fluffy_response.current_blockchain_height = arg.current_blockchain_height; @@ -2189,6 +2192,7 @@ skip: if (span.second > 0) { is_next = true; + req.blocks.reserve(hashes.size()); for (const auto &hash: hashes) { req.blocks.push_back(hash); @@ -2247,6 +2251,7 @@ skip: if (span.second > 0) { is_next = true; + req.blocks.reserve(hashes.size()); for (const auto &hash: hashes) { req.blocks.push_back(hash); @@ -2280,6 +2285,7 @@ skip: return false; } + req.blocks.reserve(req.blocks.size() + span.second); for (size_t n = 0; n < span.second; ++n) { req.blocks.push_back(context.m_needed_objects[n].first); @@ -2579,6 +2585,7 @@ skip: } context.m_needed_objects.clear(); + context.m_needed_objects.reserve(arg.m_block_ids.size()); uint64_t added = 0; std::unordered_set blocks_found; bool first = true; From 5d96c2c01404bfd20978c51493f8f4e86eedbb92 Mon Sep 17 00:00:00 2001 From: codesoap Date: Sat, 12 Dec 2020 23:18:27 +0100 Subject: [PATCH 06/12] readline_buffer: Avoid consecutive duplicates in the history --- contrib/epee/src/readline_buffer.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp index bcf499963..1047d1696 100644 --- a/contrib/epee/src/readline_buffer.cpp +++ b/contrib/epee/src/readline_buffer.cpp @@ -6,6 +6,7 @@ #include #include +static bool same_as_last_line(const std::string&); static void install_line_handler(); static void remove_line_handler(); @@ -175,8 +176,11 @@ static void handle_line(char* line) boost::trim_right(test_line); if(!test_line.empty()) { - add_history(test_line.c_str()); - history_set_pos(history_length); + if (!same_as_last_line(test_line)) + { + add_history(test_line.c_str()); + history_set_pos(history_length); + } if (test_line == "exit" || test_line == "q") exit = true; } @@ -192,6 +196,16 @@ static void handle_line(char* line) return; } +// same_as_last_line returns true, if the last line in the history is +// equal to test_line. +static bool same_as_last_line(const std::string& test_line) +{ + // Note that state->offset == state->length, when a new line was entered. + HISTORY_STATE* state = history_get_history_state(); + return state->length > 0 + && test_line.compare(state->entries[state->length-1]->line) == 0; +} + static char* completion_matches(const char* text, int state) { static size_t list_index; From de01cb77d545e97c66a747c351663c8acc294c67 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 14 Dec 2020 14:25:44 +0000 Subject: [PATCH 07/12] fuzz_tests: add a test for utf8canonical --- contrib/fuzz_testing/fuzz.sh | 4 ++-- tests/data/fuzz/utf8/UTF8_1 | 0 tests/data/fuzz/utf8/UTF8_2 | Bin 0 -> 742 bytes tests/fuzz/CMakeLists.txt | 10 +++++++++ tests/fuzz/utf8.cpp | 39 +++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/data/fuzz/utf8/UTF8_1 create mode 100644 tests/data/fuzz/utf8/UTF8_2 create mode 100644 tests/fuzz/utf8.cpp diff --git a/contrib/fuzz_testing/fuzz.sh b/contrib/fuzz_testing/fuzz.sh index efd43c231..5c88c3727 100755 --- a/contrib/fuzz_testing/fuzz.sh +++ b/contrib/fuzz_testing/fuzz.sh @@ -14,8 +14,8 @@ then exit 1 fi case "$type" in - block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof) ;; - *) echo "usage: $0 block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof"; exit 1 ;; + block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|utf8) ;; + *) echo "usage: $0 block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|utf8"; exit 1 ;; esac if test -d "fuzz-out/$type" diff --git a/tests/data/fuzz/utf8/UTF8_1 b/tests/data/fuzz/utf8/UTF8_1 new file mode 100644 index 000000000..e69de29bb diff --git a/tests/data/fuzz/utf8/UTF8_2 b/tests/data/fuzz/utf8/UTF8_2 new file mode 100644 index 0000000000000000000000000000000000000000..bb6982c4fb1b94822f4a5f07fbb2398e9546f0ab GIT binary patch literal 742 zcmaJ<*LKuU4CL8gF@MU14J6d`UUt)a97+%=Yi&Yr8+wOq=*^M0KmsYt*a@%LXCzsp zt9v|BeqlX3znaP~<>wBqxI)H74bE-VIp=n2Xx!m7HPua3-6nK5HX5dN!#UGzrCznd z15T6o!0Es5gY1!`shVTQYwJ#&Jazia+4_dYrskH`w)T$BuI`@RzO)BEnf`&nq2ZCy zvGIw?sp%O%NzR@-f8pZXCAmDmu(*^BG>2uZ;0mtd8m{98ZsHbh;|}iP9`aa4a_BxD z;2|F2F`nQlp5ZxO;3Zz+HQwMY)=|hsOuHYi-6U!5;vu3e0u`-D;|7Z8AdwbQYm-7qGXA?i};wNqVWi6yN zqL^E??6s4MMb5c`i!V!V+rQ3vVaA2i8qT=T*KpQ_feSefCK=N*Cd-(XG0Pa!GTyJJ zRSq=ZOg)nZlSY#!lV+0^lU9>9lXjC1lTMQ^lWvn9lU|cPle9_3q~Bz~WYA>DWY}cH zWYlELWZY!JWYT2HWZGoL#P_1K282dFy-%<7{Ig=c280&L6IvusXpuajCGvzOK%j5~=dIs@|dVc{*>F7cL literal 0 HcmV?d00001 diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index a599f86f8..0cf1740ad 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -218,3 +218,13 @@ set_property(TARGET tx-extra_fuzz_tests PROPERTY FOLDER "tests") +monero_add_minimal_executable(utf8_fuzz_tests utf8.cpp fuzzer.cpp) +target_link_libraries(utf8_fuzz_tests + PRIVATE + common + epee + ${Boost_THREAD_LIBRARY} + ${Boost_CHRONO_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) diff --git a/tests/fuzz/utf8.cpp b/tests/fuzz/utf8.cpp new file mode 100644 index 000000000..bf304a351 --- /dev/null +++ b/tests/fuzz/utf8.cpp @@ -0,0 +1,39 @@ +// Copyright (c) 2017-2020, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "include_base_utils.h" +#include "file_io_utils.h" +#include "common/utf8.h" +#include "fuzzer.h" + +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() + +BEGIN_SIMPLE_FUZZER() + tools::utf8canonical(std::string((const char*)buf, len), [](wint_t c)->wint_t { return c; }); +END_SIMPLE_FUZZER() From fc745d7bc9768442199f7b58a62827f85344bb37 Mon Sep 17 00:00:00 2001 From: Suriyaa Sundararuban Date: Sun, 27 Dec 2020 14:41:34 +0100 Subject: [PATCH 08/12] Update repo copyright year to 2021 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 7b9b36420..72da9414e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2020, The Monero Project +Copyright (c) 2014-2021, The Monero Project All rights reserved. From 4679168a57634a6fdbb3086702561337224e030a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 30 Dec 2020 21:07:49 +0000 Subject: [PATCH 09/12] protocol: fix wrong command in logs this is not a levin packet, this is just its payload --- src/cryptonote_protocol/levin_notify.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/cryptonote_protocol/levin_notify.cpp b/src/cryptonote_protocol/levin_notify.cpp index c23a4d2fe..1e9f3e399 100644 --- a/src/cryptonote_protocol/levin_notify.cpp +++ b/src/cryptonote_protocol/levin_notify.cpp @@ -51,14 +51,6 @@ #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net.p2p.tx" -namespace -{ - int get_command_from_message(const epee::byte_slice &msg) - { - return msg.size() >= sizeof(epee::levin::bucket_head2) ? SWAP32LE(((epee::levin::bucket_head2*)msg.data())->m_command) : 0; - } -} - namespace cryptonote { namespace levin @@ -212,7 +204,7 @@ namespace levin { const epee::byte_slice blob = make_tx_payload(std::move(txs), pad, fluff); p2p.for_connection(destination, [&blob](detail::p2p_context& context) { - on_levin_traffic(context, true, true, false, blob.size(), get_command_from_message(blob)); + on_levin_traffic(context, true, true, false, blob.size(), NOTIFY_NEW_TRANSACTIONS::ID); return true; }); return p2p.notify(NOTIFY_NEW_TRANSACTIONS::ID, epee::to_span(blob), destination); From 7dff3540f0a15cb2ae05fd0a2f16d706507a8f83 Mon Sep 17 00:00:00 2001 From: Denis Goddard Date: Thu, 31 Dec 2020 01:53:35 -0500 Subject: [PATCH 10/12] Header row for peer list in sync_info --- src/daemon/rpc_command_executor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index b99500a88..793081613 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -2275,6 +2275,7 @@ bool t_rpc_command_executor::sync_info() tools::success_msg_writer() << "Next needed pruning seed: " << res.next_needed_pruning_seed; tools::success_msg_writer() << std::to_string(res.peers.size()) << " peers"; + tools::success_msg_writer() << "Remote Host Peer_ID State Prune_Seed Height DL kB/s, Queued Blocks / MB"; for (const auto &p: res.peers) { std::string address = epee::string_tools::pad_string(p.info.address, 24); From 66f7ea2dbf92ab9e4e1b3bc94be1e0f33c0bb61d Mon Sep 17 00:00:00 2001 From: Nym Seddon Date: Thu, 31 Dec 2020 23:28:22 +0000 Subject: [PATCH 11/12] Split fuzz tests during fuzz build Only build fuzz tests in a fuzz build, and don't build other tests. Keeps fuzz compilers from instrumenting other tests, which are not fuzzed. Resolves #7232 --- tests/CMakeLists.txt | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 224784a18..85fa8f1dd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -80,17 +80,22 @@ file(COPY data/signed_monero_tx DESTINATION data) -add_subdirectory(core_tests) -add_subdirectory(fuzz) -add_subdirectory(crypto) -add_subdirectory(functional_tests) -add_subdirectory(performance_tests) -add_subdirectory(core_proxy) -add_subdirectory(unit_tests) -add_subdirectory(difficulty) -add_subdirectory(block_weight) -add_subdirectory(hash) -add_subdirectory(net_load_tests) +if (CMAKE_BUILD_TYPE STREQUAL "fuzz" OR OSSFUZZ) + add_subdirectory(fuzz) +else () + add_subdirectory(core_tests) + add_subdirectory(fuzz) + add_subdirectory(crypto) + add_subdirectory(functional_tests) + add_subdirectory(performance_tests) + add_subdirectory(core_proxy) + add_subdirectory(unit_tests) + add_subdirectory(difficulty) + add_subdirectory(block_weight) + add_subdirectory(hash) + add_subdirectory(net_load_tests) +endif() + if (BUILD_GUI_DEPS) add_subdirectory(libwallet_api_tests) endif() From 9522d668151b455e3d7b9bd98667ee2544d85d7a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 1 Jan 2021 19:54:18 +0000 Subject: [PATCH 12/12] p2p: only log to global when a blocked IP is not already blocked --- src/p2p/net_node.inl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 5efcb0867..64984eb97 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -234,6 +234,7 @@ namespace nodetool return false; const time_t now = time(nullptr); + bool added = false; CRITICAL_REGION_LOCAL(m_blocked_hosts_lock); time_t limit; @@ -244,7 +245,10 @@ namespace nodetool const std::string host_str = addr.host_str(); auto it = m_blocked_hosts.find(host_str); if (it == m_blocked_hosts.end()) + { m_blocked_hosts[host_str] = limit; + added = true; + } else if (it->second < limit || !add_only) it->second = limit; @@ -275,7 +279,10 @@ namespace nodetool conns.clear(); } - MCLOG_CYAN(el::Level::Info, "global", "Host " << host_str << " blocked."); + if (added) + MCLOG_CYAN(el::Level::Info, "global", "Host " << host_str << " blocked."); + else + MINFO("Host " << host_str << " block time updated."); return true; } //-----------------------------------------------------------------------------------