aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2018-07-19 18:29:25 -0700
committerAndrew Chow <achow101-github@achow101.com>2018-07-19 18:29:25 -0700
commit41df035ee1694715ee1e0f89b08ac8c73987807b (patch)
tree0b36b70f49064281807012954213f2a4d63f8a33 /src/script
parentaba2e666d7fd42f40c0bf4196dbff66a48eaf97b (diff)
Check that PSBT keys are the correct length
Checks that all of the one byte type keys are actually one byte and throw an error if they are not. Add tests for each type to check for this behavior.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/sign.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/script/sign.h b/src/script/sign.h
index e3a6196b28..f35db99160 100644
--- a/src/script/sign.h
+++ b/src/script/sign.h
@@ -286,12 +286,16 @@ struct PSBTInput
case PSBT_IN_NON_WITNESS_UTXO:
if (non_witness_utxo) {
throw std::ios_base::failure("Duplicate Key, input non-witness utxo already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Non-witness utxo key is more than one byte type");
}
UnserializeFromVector(s, non_witness_utxo);
break;
case PSBT_IN_WITNESS_UTXO:
if (!witness_utxo.IsNull()) {
throw std::ios_base::failure("Duplicate Key, input witness utxo already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Witness utxo key is more than one byte type");
}
UnserializeFromVector(s, witness_utxo);
break;
@@ -321,6 +325,8 @@ struct PSBTInput
case PSBT_IN_SIGHASH:
if (sighash_type > 0) {
throw std::ios_base::failure("Duplicate Key, input sighash type already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Sighash type key is more than one byte type");
}
UnserializeFromVector(s, sighash_type);
break;
@@ -328,6 +334,8 @@ struct PSBTInput
{
if (!redeem_script.empty()) {
throw std::ios_base::failure("Duplicate Key, input redeemScript already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Input redeemScript key is more than one byte type");
}
s >> redeem_script;
break;
@@ -336,6 +344,8 @@ struct PSBTInput
{
if (!witness_script.empty()) {
throw std::ios_base::failure("Duplicate Key, input witnessScript already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Input witnessScript key is more than one byte type");
}
s >> witness_script;
break;
@@ -349,6 +359,8 @@ struct PSBTInput
{
if (!final_script_sig.empty()) {
throw std::ios_base::failure("Duplicate Key, input final scriptSig already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Final scriptSig key is more than one byte type");
}
s >> final_script_sig;
break;
@@ -357,6 +369,8 @@ struct PSBTInput
{
if (!final_script_witness.IsNull()) {
throw std::ios_base::failure("Duplicate Key, input final scriptWitness already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Final scriptWitness key is more than one byte type");
}
UnserializeFromVector(s, final_script_witness.stack);
break;
@@ -444,6 +458,8 @@ struct PSBTOutput
{
if (!redeem_script.empty()) {
throw std::ios_base::failure("Duplicate Key, output redeemScript already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Output redeemScript key is more than one byte type");
}
s >> redeem_script;
break;
@@ -452,6 +468,8 @@ struct PSBTOutput
{
if (!witness_script.empty()) {
throw std::ios_base::failure("Duplicate Key, output witnessScript already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Output witnessScript key is more than one byte type");
}
s >> witness_script;
break;
@@ -566,6 +584,8 @@ struct PartiallySignedTransaction
{
if (tx) {
throw std::ios_base::failure("Duplicate Key, unsigned tx already provided");
+ } else if (key.size() != 1) {
+ throw std::ios_base::failure("Global unsigned tx key is more than one byte type");
}
CMutableTransaction mtx;
UnserializeFromVector(s, mtx);