Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 401573f

Browse files
VG-3617: Fix some weird crash in wd integration tests (#858)
* fix: weird crash in wd integration tests when loading libcore. The fix is to avoid using std::regex constructor of global static variables using lazy initialization of static variables. The crash happens when the WD tries to load the libcore and static regex variable are being initialized. It looks like the locale is not yet correctly defined and the regex constructor does not accept this case. * fix: btc transaction incorrect parsing when values are string Handle string type for some fields in BTC transaction returned by explorers. * fix: possible memory leak in Base58 * ci: bump patch version
1 parent aca69c9 commit 401573f

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ include_what_you_use() # add cmake conf option IWYU=ON to activate
4444
# The project version number.
4545
set(VERSION_MAJOR 4 CACHE STRING "Project major version number.")
4646
set(VERSION_MINOR 1 CACHE STRING "Project minor version number.")
47-
set(VERSION_PATCH 5 CACHE STRING "Project patch version number.")
47+
set(VERSION_PATCH 6 CACHE STRING "Project patch version number.")
4848
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH)
4949

5050
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)

core/src/math/Base58.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <utils/hex.h>
3636
#include <functional>
3737
#include <crypto/Keccak.h>
38+
#include <vector>
3839

3940
using namespace ledger::core;
4041
static const std::string DIGITS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
@@ -62,7 +63,7 @@ std::string ledger::core::Base58::encode(const std::vector<uint8_t> &bytes,
6263
pend = len;
6364
while (pbegin != pend && !bytes[pbegin]) pbegin = ++zeros;
6465
const int size = 1 + iFactor * (double)(pend - pbegin);
65-
unsigned char* b58 = new unsigned char[size];
66+
std::vector<unsigned char> b58(size, 0);
6667
for (int i = 0; i < size; i++) b58[i] = 0;
6768
while (pbegin != pend) {
6869
unsigned int carry = bytes[pbegin];
@@ -82,7 +83,6 @@ std::string ledger::core::Base58::encode(const std::vector<uint8_t> &bytes,
8283
int ri = 0;
8384
while (ri < zeros) { result += base58Dictionary[0]; ri++; }
8485
for (; it2 < size; ++it2) result += base58Dictionary[b58[it2]];
85-
delete[] b58;
8686
return result;
8787
}
8888

core/src/utils/DateUtils.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ namespace {
5252
{"Dec", "12"},
5353
};
5454

55-
const std::regex PARSE_JSON_DATE_REGEX("([0-9]+)-([0-9]+)-([0-9]+)T([0-9]+):([0-9]+):([0-9]+)[\\.0-9]*([Z]?)");
56-
const std::regex FORMAT_JSON_DATE_REGEX("([0-9]+)-([a-zA-Z]+)-([0-9]+) ([0-9]+):([0-9]+):([0-9]+)[\\.0-9]*([Z]?)");
55+
constexpr auto PARSE_JSON_DATE_REGEX("([0-9]+)-([0-9]+)-([0-9]+)T([0-9]+):([0-9]+):([0-9]+)[\\.0-9]*([Z]?)");
56+
constexpr auto FORMAT_JSON_DATE_REGEX("([0-9]+)-([a-zA-Z]+)-([0-9]+) ([0-9]+):([0-9]+):([0-9]+)[\\.0-9]*([Z]?)");
5757
}
5858

5959
#if defined(_WIN32) || defined(_WIN64)
@@ -67,9 +67,11 @@ namespace {
6767
namespace ledger {
6868
namespace core {
6969
std::chrono::system_clock::time_point ledger::core::DateUtils::fromJSON(const std::string &str) {
70+
static const std::regex parseJsonDateRegex {PARSE_JSON_DATE_REGEX};
71+
7072
std::cmatch what;
7173

72-
if (regex_match(str.c_str(), what, PARSE_JSON_DATE_REGEX)) {
74+
if (regex_match(str.c_str(), what, parseJsonDateRegex)) {
7375
auto year = boost::lexical_cast<unsigned int>(std::string(what[1].first, what[1].second));
7476
auto month = boost::lexical_cast<unsigned int>(std::string(what[2].first, what[2].second));
7577
auto day = boost::lexical_cast<unsigned int>(std::string(what[3].first, what[3].second));
@@ -104,10 +106,11 @@ namespace ledger {
104106
}
105107

106108
std::string ledger::core::DateUtils::formatDateFromJSON(const std::string &str) {
109+
static const std::regex formatJsonDateRegex {FORMAT_JSON_DATE_REGEX};
107110

108111
std::cmatch what;
109112

110-
if (regex_match(str.c_str(), what, FORMAT_JSON_DATE_REGEX)) {
113+
if (regex_match(str.c_str(), what, formatJsonDateRegex)) {
111114
auto year = boost::lexical_cast<unsigned int>(std::string(what[1].first, what[1].second));
112115
auto month = boost::lexical_cast<std::string>(std::string(what[2].first, what[2].second));
113116
auto day = boost::lexical_cast<unsigned int>(std::string(what[3].first, what[3].second));

core/src/wallet/bitcoin/explorers/BitcoinLikeBlockchainExplorer.hpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,7 @@ namespace ledger {
9999
confirmations = -1;
100100
}
101101

102-
BitcoinLikeBlockchainExplorerTransaction(const BitcoinLikeBlockchainExplorerTransaction &cpy) {
103-
this->confirmations = cpy.confirmations;
104-
this->version = cpy.version;
105-
this->outputs = cpy.outputs;
106-
this->inputs = cpy.inputs;
107-
this->receivedAt = cpy.receivedAt;
108-
this->lockTime = cpy.lockTime;
109-
this->fees = cpy.fees;
110-
this->hash = cpy.hash;
111-
this->block = cpy.block;
112-
}
102+
BitcoinLikeBlockchainExplorerTransaction(const BitcoinLikeBlockchainExplorerTransaction &cpy) = default;
113103
};
114104

115105
class BitcoinLikeBlockchainExplorer : public ConfigurationMatchable,

core/src/wallet/bitcoin/explorers/api/InputParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ namespace ledger {
8888
_input->coinbase = Option<std::string>(value);
8989
} else if (_lastKey == "value") {
9090
_input->value = Option<BigInt>(BigInt::fromString(value));
91+
} else if (_lastKey == "sequence") {
92+
_input->sequence = BigInt::fromString(value).toUint64();
9193
}
9294
return true;
9395
}

core/src/wallet/bitcoin/explorers/api/TransactionParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ namespace ledger {
169169
}
170170
else if (_lastKey == "received_at") {
171171
_transaction->receivedAt = DateUtils::fromJSON(value);
172+
} else if (_lastKey == "fees") {
173+
BigInt intValue = BigInt::fromString(value);
174+
_transaction->fees = Option<BigInt>(intValue);
172175
}
176+
173177
return true;
174178
}
175179
}

0 commit comments

Comments
 (0)