aboutsummaryrefslogtreecommitdiff
path: root/src/key.cpp
diff options
context:
space:
mode:
authorAntoine Poinsot <darosior@protonmail.com>2022-07-19 11:58:16 +0200
committerAntoine Poinsot <darosior@protonmail.com>2022-08-04 11:32:26 +0200
commitfb9faffae3a26b8aed8b671864ba679747163019 (patch)
tree5f3e9a35cf03804330e53a28bb33c2a416e06fd5 /src/key.cpp
parent8dc6670ce159c2b080e9f735c6603a601d40b6ac (diff)
downloadbitcoin-fb9faffae3a26b8aed8b671864ba679747163019.tar.xz
extended keys: fail to derive too large depth instead of wrapping around
This issue was reported to me by Marco Falke, and found with the descriptor_parse fuzz target.
Diffstat (limited to 'src/key.cpp')
-rw-r--r--src/key.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/key.cpp b/src/key.cpp
index 9b0971a2dd..199808505d 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -333,6 +333,7 @@ bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const
}
bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
+ if (nDepth == std::numeric_limits<unsigned char>::max()) return false;
out.nDepth = nDepth + 1;
CKeyID id = key.GetPubKey().GetID();
memcpy(out.vchFingerprint, &id, 4);