From 237b6da0ca9ea5507dc8caebcec26867a30f9d49 Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 23 Mar 2015 17:52:34 +0300 Subject: [PATCH 1/2] Transaction Data Must Be Array +libsecp256k1test --- libethereum/Transaction.cpp | 4 ++++ test/ttTransactionTestFiller.json | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 31a7f74a9..9a5e7fb3f 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -68,6 +68,10 @@ Transaction::Transaction(bytesConstRef _rlpData, CheckSignature _checkSig) m_type = rlp[field = 3].isEmpty() ? ContractCreation : MessageCall; m_receiveAddress = rlp[field = 3].isEmpty() ? Address() : rlp[field = 3].toHash
(RLP::VeryStrict); m_value = rlp[field = 4].toInt(); + + if (rlp[field = 5].isList()) + BOOST_THROW_EXCEPTION(BadRLP() << errinfo_comment("transaction data RLP must be an array")); + m_data = rlp[field = 5].toBytes(); byte v = rlp[field = 6].toInt() - 27; h256 r = rlp[field = 7].toInt(); diff --git a/test/ttTransactionTestFiller.json b/test/ttTransactionTestFiller.json index 105b64abc..4f8005c5f 100644 --- a/test/ttTransactionTestFiller.json +++ b/test/ttTransactionTestFiller.json @@ -511,6 +511,7 @@ "s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" } }, + "unpadedRValue": { "transaction": { "nonce": "13", @@ -523,5 +524,19 @@ "v": "28", "value": "" } + }, + + "libsecp256k1test": { + "transaction": { + "nonce": "", + "gasPrice": "0x09184e72a000", + "gasLimit": "0x1388", + "to": "", + "data": "", + "r": "44", + "s": "4", + "v": "27", + "value": "" + } } } From 4a436715cfa38b699a1f58c077d8e3717f233f6b Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 23 Mar 2015 23:50:04 +0300 Subject: [PATCH 2/2] Exceptions --- libethereum/Transaction.cpp | 2 +- test/transaction.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 9a5e7fb3f..502f089fb 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -69,7 +69,7 @@ Transaction::Transaction(bytesConstRef _rlpData, CheckSignature _checkSig) m_receiveAddress = rlp[field = 3].isEmpty() ? Address() : rlp[field = 3].toHash
(RLP::VeryStrict); m_value = rlp[field = 4].toInt(); - if (rlp[field = 5].isList()) + if (!rlp[field = 5].isData()) BOOST_THROW_EXCEPTION(BadRLP() << errinfo_comment("transaction data RLP must be an array")); m_data = rlp[field = 5].toBytes(); diff --git a/test/transaction.cpp b/test/transaction.cpp index 77f6ecdaf..4c57326ba 100644 --- a/test/transaction.cpp +++ b/test/transaction.cpp @@ -48,6 +48,13 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin) if (!txFromRlp.signature().isValid()) BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") ); } + catch(Exception const& _e) + { + cnote << i.first; + cnote << "Transaction Exception: " << diagnostic_information(_e); + BOOST_CHECK_MESSAGE(o.count("transaction") == 0, "A transaction object should not be defined because the RLP is invalid!"); + continue; + } catch(...) { BOOST_CHECK_MESSAGE(o.count("transaction") == 0, "A transaction object should not be defined because the RLP is invalid!");