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:
@@ -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{};
|
||||
|
||||
Reference in New Issue
Block a user