From 5c449913afcfee17f40418980be9ae297a17b846 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Fri, 15 Jan 2021 11:18:36 +0100 Subject: [PATCH 1/2] Fixed solo mining It was broken since 6.7.0 --- src/base/net/stratum/DaemonClient.cpp | 4 ++-- src/base/tools/Cvt.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index 8b4d0fb69..554ee8a89 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -104,7 +104,7 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result) # ifdef XMRIG_PROXY_PROJECT memcpy(data + 78, result.nonce, 8); # else - Cvt::toHex(data + 78, 9, reinterpret_cast(&result.nonce), 4); + Cvt::toHex(data + 78, 8, reinterpret_cast(&result.nonce), 4); # endif using namespace rapidjson; @@ -227,7 +227,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) m_blockhashingblob = Json::getString(params, "blockhashing_blob"); if (m_apiVersion == API_DERO) { const uint64_t offset = Json::getUint64(params, "reserved_offset"); - Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2 + 1, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize); + Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize); } if (blocktemplate.isNull() || !job.setBlob(m_blockhashingblob)) { diff --git a/src/base/tools/Cvt.cpp b/src/base/tools/Cvt.cpp index c80c022c0..0c9cdbf1e 100644 --- a/src/base/tools/Cvt.cpp +++ b/src/base/tools/Cvt.cpp @@ -46,7 +46,7 @@ static char *cvt_bin2hex(char *const hex, const size_t hex_maxlen, const unsigne int b; int c; - if (bin_len >= SIZE_MAX / 2 || hex_maxlen <= bin_len * 2U) { + if (bin_len >= SIZE_MAX / 2 || hex_maxlen < bin_len * 2U) { return nullptr; /* LCOV_EXCL_LINE */ } @@ -60,7 +60,10 @@ static char *cvt_bin2hex(char *const hex, const size_t hex_maxlen, const unsigne hex[i * 2U + 1U] = (char) x; i++; } - hex[i * 2U] = 0U; + + if (i * 2U < hex_maxlen) { + hex[i * 2U] = 0U; + } return hex; } From 7da04c6a2c1e3ffd7c858bc472678a819190977a Mon Sep 17 00:00:00 2001 From: SChernykh Date: Fri, 15 Jan 2021 12:46:27 +0100 Subject: [PATCH 2/2] Always use cvt_bin2hex --- src/base/tools/Cvt.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/base/tools/Cvt.cpp b/src/base/tools/Cvt.cpp index 0c9cdbf1e..be46bc0c5 100644 --- a/src/base/tools/Cvt.cpp +++ b/src/base/tools/Cvt.cpp @@ -140,7 +140,6 @@ static int cvt_hex2bin(unsigned char *const bin, const size_t bin_maxlen, const return ret; } -#define sodium_bin2hex cvt_bin2hex #define sodium_hex2bin cvt_hex2bin #endif @@ -218,7 +217,7 @@ xmrig::Buffer xmrig::Cvt::fromHex(const char *in, size_t size) bool xmrig::Cvt::toHex(char *hex, size_t hex_maxlen, const uint8_t *bin, size_t bin_len) { - return sodium_bin2hex(hex, hex_maxlen, bin, bin_len) != nullptr; + return cvt_bin2hex(hex, hex_maxlen, bin, bin_len) != nullptr; }