From 66507021e0f5baa1a04cad22d2995adbc5e363fc Mon Sep 17 00:00:00 2001 From: Michael Contreras Date: Tue, 5 May 2020 23:27:59 -0400 Subject: [PATCH] pool:rpc_on_wallet_transferred: check underflow Check against balance integer underflow in rpc_on_wallet_transferred. --- src/pool.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pool.c b/src/pool.c index 573e398..3f7da04 100644 --- a/src/pool.c +++ b/src/pool.c @@ -1953,7 +1953,18 @@ rpc_on_wallet_transferred(const char* data, rpc_callback_t *callback) continue; } uint64_t current_amount = *(uint64_t*)val.mv_data; - current_amount -= payment->amount; + + if (current_amount >= payment->amount) + { + current_amount -= payment->amount; + } + else + { + log_error("Payment was more than balance: %"PRIu64" > %"PRIu64, + payment->amount, current_amount); + current_amount = 0; + } + if (error) { log_warn("Error seen on transfer for %s with amount %"PRIu64,