diff options
author | Andrew Chow <achow101-github@achow101.com> | 2018-10-02 20:33:31 -0400 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-12-03 10:32:58 -0800 |
commit | a3fe125490978a684528c40fc9a15ccdfdf2c92a (patch) | |
tree | 8a12ce2b26210bf1bc1d666420e6674158561763 /src/script/sign.h | |
parent | 3362a95be360dd798c32fc0184c0fe67da6ef43a (diff) | |
download | bitcoin-a3fe125490978a684528c40fc9a15ccdfdf2c92a.tar.xz |
check that a separator is found for psbt inputs, outputs, and global map
Github-Pull: #14377
Rebased-From: 4fb3388db95f408566e43ebb9736842cfbff0a7d
Diffstat (limited to 'src/script/sign.h')
-rw-r--r-- | src/script/sign.h | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/script/sign.h b/src/script/sign.h index 245b15410f..2b45df85a0 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -286,6 +286,7 @@ struct PSBTInput template <typename Stream> inline void Unserialize(Stream& s) { // Read loop + bool found_sep = false; while(!s.empty()) { // Read std::vector<unsigned char> key; @@ -293,7 +294,10 @@ struct PSBTInput // the key is empty if that was actually a separator byte // This is a special case for key lengths 0 as those are not allowed (except for separator) - if (key.empty()) return; + if (key.empty()) { + found_sep = true; + break; + } // First byte of key is the type unsigned char type = key[0]; @@ -408,6 +412,10 @@ struct PSBTInput break; } } + + if (!found_sep) { + throw std::ios_base::failure("Separator is missing at the end of an input map"); + } } template <typename Stream> @@ -461,6 +469,7 @@ struct PSBTOutput template <typename Stream> inline void Unserialize(Stream& s) { // Read loop + bool found_sep = false; while(!s.empty()) { // Read std::vector<unsigned char> key; @@ -468,7 +477,10 @@ struct PSBTOutput // the key is empty if that was actually a separator byte // This is a special case for key lengths 0 as those are not allowed (except for separator) - if (key.empty()) return; + if (key.empty()) { + found_sep = true; + break; + } // First byte of key is the type unsigned char type = key[0]; @@ -513,6 +525,10 @@ struct PSBTOutput } } } + + if (!found_sep) { + throw std::ios_base::failure("Separator is missing at the end of an output map"); + } } template <typename Stream> @@ -588,6 +604,7 @@ struct PartiallySignedTransaction } // Read global data + bool found_sep = false; while(!s.empty()) { // Read std::vector<unsigned char> key; @@ -595,7 +612,10 @@ struct PartiallySignedTransaction // the key is empty if that was actually a separator byte // This is a special case for key lengths 0 as those are not allowed (except for separator) - if (key.empty()) break; + if (key.empty()) { + found_sep = true; + break; + } // First byte of key is the type unsigned char type = key[0]; @@ -635,6 +655,10 @@ struct PartiallySignedTransaction } } + if (!found_sep) { + throw std::ios_base::failure("Separator is missing at the end of the global map"); + } + // Make sure that we got an unsigned tx if (!tx) { throw std::ios_base::failure("No unsigned transcation was provided"); |