From d0044c4b32f2c7df90febc0c3612791fd8d327a0 Mon Sep 17 00:00:00 2001
From: Richard Chapman <rchapman@hpccsystems.com>
Date: Wed, 14 Aug 2024 10:56:38 +0100
Subject: [PATCH] HPCC-32430 Fix warnings in libbase58

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
---
 system/libbase58/base58.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/system/libbase58/base58.c b/system/libbase58/base58.c
index 4c1f5751ab4..874b92b758b 100644
--- a/system/libbase58/base58.c
+++ b/system/libbase58/base58.c
@@ -137,9 +137,9 @@ int b58check(const void *bin, size_t binsz, const char *base58str, size_t b58sz)
         return -1;
 
     // Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end)
-    for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i)
+    for (i = 0; i < binsz && binc[i] == '\0' && i < b58sz && base58str[i] == '1'; ++i)
     {}  // Just finding the end of zeros, nothing to do in loop
-    if (binc[i] == '\0' || base58str[i] == '1')
+    if (i >= binsz || binc[i] == '\0' || i >= b58sz || base58str[i] == '1')
         return -3;
 
     return binc[0];