aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-03-31 10:18:14 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-03-31 10:21:38 +0200
commitde301b048810c52df3c04bdae6b44a4933016bab (patch)
tree6e7db5cc3ca8c76d23fed23df9ca6a72edf4b99a
parent8e4f7e72410df3ba430082c7cf385f26fd75b033 (diff)
parent19ecd1e2e13514c8a92a2a4337c2568c3d5d13e5 (diff)
downloadbitcoin-de301b048810c52df3c04bdae6b44a4933016bab.tar.xz
Merge #10130: bitcoin-tx input verification (awemany, jnewbery)
19ecd1e Add tests for bitcoin-tx input checking (John Newbery) 21704f6 Check stderr when testing bitcoin-tx (John Newbery) eb66bf9 bitcoin-tx: Fix missing range check (Awemany) Tree-SHA512: 08c6153cf7dd5e0ecd23e24d81af4c0f17534d484179dd91dcd78d42df14c91284341d31cc695469a64c507bce72c34231748b7cabb7df8f1051d228fb0a62c5
-rw-r--r--src/bitcoin-tx.cpp6
-rw-r--r--test/util/bctest.py12
-rw-r--r--test/util/data/bitcoin-util-test.json36
3 files changed, 54 insertions, 0 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index 61e0eb74e6..83b855cbcf 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -242,6 +242,9 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strIn
std::vector<std::string> vStrInputParts;
boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
+ if (vStrInputParts.size() != 2)
+ throw std::runtime_error("TX output missing or too many separators");
+
// Extract and validate VALUE
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
@@ -264,6 +267,9 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str
std::vector<std::string> vStrInputParts;
boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
+ if (vStrInputParts.size() < 2 || vStrInputParts.size() > 3)
+ throw std::runtime_error("TX output missing or too many separators");
+
// Extract and validate VALUE
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
diff --git a/test/util/bctest.py b/test/util/bctest.py
index dfe3a123d1..b17cf77ae3 100644
--- a/test/util/bctest.py
+++ b/test/util/bctest.py
@@ -102,6 +102,18 @@ def bctest(testDir, testObj, buildenv):
logging.error("Return code mismatch for " + outputFn)
raise Exception
+ if "error_txt" in testObj:
+ want_error = testObj["error_txt"]
+ # Compare error text
+ # TODO: ideally, we'd compare the strings exactly and also assert
+ # That stderr is empty if no errors are expected. However, bitcoin-tx
+ # emits DISPLAY errors when running as a windows application on
+ # linux through wine. Just assert that the expected error text appears
+ # somewhere in stderr.
+ if want_error not in outs[1]:
+ logging.error("Error mismatch:\n" + "Expected: " + want_error + "\nReceived: " + outs[1].rstrip())
+ raise Exception
+
def bctester(testDir, input_basename, buildenv):
""" Loads and parses the input file, runs all tests and reports results"""
input_filename = testDir + "/" + input_basename
diff --git a/test/util/data/bitcoin-util-test.json b/test/util/data/bitcoin-util-test.json
index a80ab51901..b61a4f7f8f 100644
--- a/test/util/data/bitcoin-util-test.json
+++ b/test/util/data/bitcoin-util-test.json
@@ -42,6 +42,7 @@
"args": ["-", "delin=31"],
"input": "tx394b54bb.hex",
"return_code": 1,
+ "error_txt": "error: Invalid TX input index '31'",
"description": "Attempts to delete an input with a bad index from a transaction. Expected to fail."
},
{ "exec": "./bitcoin-tx",
@@ -60,6 +61,7 @@
"args": ["-", "delout=2"],
"input": "tx394b54bb.hex",
"return_code": 1,
+ "error_txt": "error: Invalid TX output index '2'",
"description": "Attempts to delete an output with a bad index from a transaction. Expected to fail."
},
{ "exec": "./bitcoin-tx",
@@ -77,6 +79,38 @@
{ "exec": "./bitcoin-tx",
"args":
["-create",
+ "outaddr=1"],
+ "return_code": 1,
+ "error_txt": "error: TX output missing or too many separators",
+ "description": "Malformed outaddr argument (no address specified). Expected to fail."
+ },
+ { "exec": "./bitcoin-tx",
+ "args":
+ ["-create",
+ "outaddr=1:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o:garbage"],
+ "return_code": 1,
+ "error_txt": "error: TX output missing or too many separators",
+ "description": "Malformed outaddr argument (too many separators). Expected to fail."
+ },
+ { "exec": "./bitcoin-tx",
+ "args":
+ ["-create",
+ "outpubkey=0"],
+ "return_code": 1,
+ "error_txt": "error: TX output missing or too many separators",
+ "description": "Malformed outpubkey argument (no pubkey specified). Expected to fail."
+ },
+ { "exec": "./bitcoin-tx",
+ "args":
+ ["-create",
+ "outpubkey=0:02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397:W:non53nse"],
+ "return_code": 1,
+ "error_txt": "error: TX output missing or too many separators",
+ "description": "Malformed outpubkey argument (too many separators). Expected to fail."
+ },
+ { "exec": "./bitcoin-tx",
+ "args":
+ ["-create",
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
"in=bf829c6bcf84579331337659d31f89dfd138f7f7785802d5501c92333145ca7c:18",
"in=22a6f904655d53ae2ff70e701a0bbd90aa3975c0f40bfc6cc996a9049e31cdfc:1",
@@ -233,6 +267,7 @@
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
"outdata=4:badhexdata"],
"return_code": 1,
+ "error_txt": "error: invalid TX output data",
"description": "Attempts to create a new transaction with one input and an output with malformed hex data. Expected to fail"
},
{ "exec": "./bitcoin-tx",
@@ -241,6 +276,7 @@
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
"outdata=badhexdata"],
"return_code": 1,
+ "error_txt": "error: invalid TX output data",
"description": "Attempts to create a new transaction with one input and an output with no value and malformed hex data. Expected to fail"
},
{ "exec": "./bitcoin-tx",