From fa2b52af32f6a4b9c22c270f36e92960c29ef364 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 13 May 2019 15:38:10 -0400 Subject: [PATCH] Disallow extended encoding for non-witness transactions (take 3) --- src/net_processing.cpp | 21 ++++++++++----------- test/functional/p2p_segwit.py | 26 +++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index b3facdcd3..3254c6a19 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3288,23 +3288,22 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic& inter if (m_enable_bip61) { connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_MALFORMED, std::string("error parsing message"))); } - if (strstr(e.what(), "end of data")) - { + if (strstr(e.what(), "end of data")) { // Allow exceptions from under-length message on vRecv LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught, normally caused by a message being shorter than its stated length\n", __func__, SanitizeString(strCommand), nMessageSize, e.what()); - } - else if (strstr(e.what(), "size too large")) - { + } else if (strstr(e.what(), "size too large")) { // Allow exceptions from over-long size LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what()); - } - else if (strstr(e.what(), "non-canonical ReadCompactSize()")) - { + } else if (strstr(e.what(), "non-canonical ReadCompactSize()")) { // Allow exceptions from non-canonical encoding LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what()); - } - else - { + } else if (strstr(e.what(), "Superfluous witness record")) { + // Allow exceptions from illegal witness encoding + LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what()); + } else if (strstr(e.what(), "Unknown transaction optional data")) { + // Allow exceptions from unknown witness encoding + LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what()); + } else { PrintExceptionContinue(&e, "ProcessMessages()"); } } diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py index 000c30646..df0f9fa36 100755 --- a/test/functional/p2p_segwit.py +++ b/test/functional/p2p_segwit.py @@ -2038,9 +2038,9 @@ class SegWitTest(BitcoinTestFramework): # TODO: test p2sh sigop counting def test_superfluous_witness(self): - # Serialization of tx that puts witness flag to 1 always + # Serialization of tx that puts witness flag to 3 always def serialize_with_bogus_witness(tx): - flags = 1 + flags = 3 r = b"" r += struct.pack("