mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-29 09:55:49 +02:00
check that a separator is found for psbt inputs, outputs, and global map
Github-Pull: #14377
Rebased-From: 4fb3388db9
This commit is contained in:
committed by
Pieter Wuille
parent
3362a95be3
commit
a3fe125490
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user