Skip to content

Commit 23a4486

Browse files
author
Ed Gamble
committed
DROID-340: Java interface - In BRCoreAddress limit addresses to 35 characters
1 parent 4757558 commit 23a4486

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Java/com_breadwallet_core_BRCoreAddress.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ Java_com_breadwallet_core_BRCoreAddress_createCoreAddress
3737
BRAddress *address = (BRAddress *) calloc (1, sizeof (BRAddress));
3838

3939
size_t stringLen = (size_t) (*env)->GetStringLength (env, stringObject);
40-
//assert (stringLen <= 36);
40+
size_t stringLenMax = sizeof (address->s) - 1;
41+
42+
// Do not overflow address->s
43+
if (stringLen > stringLenMax)
44+
stringLen = stringLenMax;
4145

4246
const char *stringChars = (const char *) (*env)->GetStringUTFChars (env, stringObject, 0);
4347
memcpy(address->s, stringChars, stringLen);

Java/root/com/breadwallet/core/test/BRWalletManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ private static void runKeyTests() {
278278
System.out.println(" " + key.address());
279279

280280
addr1 = new BRCoreAddress(key.address());
281+
assert (addr1.isValid());
281282

282283
byte[] script = addr1.getPubKeyScript();
283284

@@ -294,6 +295,16 @@ private static void runKeyTests() {
294295
String bitcoinAddr3 = BRCoreAddress.bcashDecodeBitcoin("bitcoincash:qzfhn2f7dwsfqdf6nlu07rw6c3ssqe9rm5a5y8tgm9");
295296
assert (null != bitcoinAddr3 && !bitcoinAddr3.isEmpty());
296297

298+
System.out.println (" Mihail's BCH: " + "bitcoincash:qzc93708k7x0w3gr32thxc5fla38xf8x8vq8h33fva");
299+
System.out.println (" Mihail's BTC: " + BRCoreAddress.bcashDecodeBitcoin("bitcoincash:qzc93708k7x0w3gr32thxc5fla38xf8x8vq8h33fva"));
300+
301+
BRCoreAddress addrX1 = new BRCoreAddress(
302+
"bitcoincash:qzc93708k7x0w3gr32thxc5fla38xf8x8vq8h33fva");
303+
assert (!addrX1.isValid());
304+
BRCoreAddress addrX2 = new BRCoreAddress(
305+
BRCoreAddress.bcashDecodeBitcoin("bitcoincash:qzc93708k7x0w3gr32thxc5fla38xf8x8vq8h33fva"));
306+
assert (addrX2.isValid());
307+
297308
//
298309
//
299310
//

0 commit comments

Comments
 (0)