Fix potential division by zero in stratum target calculation, Refactored the nested division expression, intermediate variables with safety checks, prevents potential undefined

behavior that was causing UBSAN crashes
This commit is contained in:
Matt Hess
2025-12-19 00:29:18 +00:00
parent 418a2d363c
commit d509947157
2 changed files with 11 additions and 5 deletions
+7 -1
View File
@@ -438,7 +438,13 @@ bool StratumServer::on_submit(StratumClient* client, uint32_t id, const char* jo
if (target >= TARGET_4_BYTES_LIMIT) {
// "Low diff share" fix: adjust target to the same value as XMRig would use
target = std::numeric_limits<uint64_t>::max() / (std::numeric_limits<uint32_t>::max() / (target >> 32));
const uint64_t upper_bits = target >> 32;
if (upper_bits > 0) {
const uint64_t divisor = std::numeric_limits<uint32_t>::max() / upper_bits;
if (divisor > 0) {
target = std::numeric_limits<uint64_t>::max() / divisor;
}
}
}
SubmittedShare share{};