aboutsummaryrefslogtreecommitdiff
path: root/src/util/asmap.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2020-04-02 18:17:55 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2020-04-08 16:26:06 -0700
commit5feefbe6e7b6cdd809eba4074d41dc95a7035f7e (patch)
tree86b3b8ce9c7165daede3a8ecf01b43bde2604cf3 /src/util/asmap.cpp
parent2b3dbfa5a63cb5a6625ec00294ebd933800f0255 (diff)
downloadbitcoin-5feefbe6e7b6cdd809eba4074d41dc95a7035f7e.tar.xz
Improve asmap Interpret checks and document failures
Diffstat (limited to 'src/util/asmap.cpp')
-rw-r--r--src/util/asmap.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp
index 5b21d01f3a..e428ec8138 100644
--- a/src/util/asmap.cpp
+++ b/src/util/asmap.cpp
@@ -91,9 +91,9 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
} else if (opcode == Instruction::JUMP) {
jump = DecodeJump(pos, endpos);
if (jump == INVALID) break; // Jump offset straddles EOF
- if (bits == 0) break;
+ if (bits == 0) break; // No input bits left
+ if (jump >= endpos - pos) break; // Jumping past EOF
if (ip[ip.size() - bits]) {
- if (jump >= endpos - pos) break;
pos += jump;
}
bits--;
@@ -101,8 +101,8 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
match = DecodeMatch(pos, endpos);
if (match == INVALID) break; // Match bits straddle EOF
matchlen = CountBits(match) - 1;
+ if (bits < matchlen) break; // Not enough input bits
for (uint32_t bit = 0; bit < matchlen; bit++) {
- if (bits == 0) break;
if ((ip[ip.size() - bits]) != ((match >> (matchlen - 1 - bit)) & 1)) {
return default_asn;
}
@@ -115,5 +115,6 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
break; // Instruction straddles EOF
}
}
+ // Reached EOF without RETURN, or aborted (see any of the breaks above).
return 0; // 0 is not a valid ASN
}