Skip to content

Commit 37d30ec

Browse files
committed
Merge pull request #3413
d31ad26 qt: Add missing lock in WalletModel::listCoins (Wladimir J. van der Laan) 28352af qt: protect SetAddressBook with cs_wallet lock everywhere (Wladimir J. van der Laan) aaf8d15 qt: Add missing LOCKs for locked coin functions (Wladimir J. van der Laan) 4757e92 qt: add missing cs_wallet lock in AddressTableModel::setData (Wladimir J. van der Laan)
2 parents 7aedb91 + d31ad26 commit 37d30ec

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -244,49 +244,46 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
244244

245245
if(role == Qt::EditRole)
246246
{
247-
switch(index.column())
247+
LOCK(wallet->cs_wallet); /* For SetAddressBook / DelAddressBook */
248+
CTxDestination curAddress = CBitcoinAddress(rec->address.toStdString()).Get();
249+
if(index.column() == Label)
248250
{
249-
case Label:
250251
// Do nothing, if old label == new label
251252
if(rec->label == value.toString())
252253
{
253254
editStatus = NO_CHANGES;
254255
return false;
255256
}
256-
wallet->SetAddressBook(CBitcoinAddress(rec->address.toStdString()).Get(), value.toString().toStdString(), strPurpose);
257-
break;
258-
case Address:
259-
// Do nothing, if old address == new address
260-
if(CBitcoinAddress(rec->address.toStdString()) == CBitcoinAddress(value.toString().toStdString()))
257+
wallet->SetAddressBook(curAddress, value.toString().toStdString(), strPurpose);
258+
} else if(index.column() == Address) {
259+
CTxDestination newAddress = CBitcoinAddress(value.toString().toStdString()).Get();
260+
// Refuse to set invalid address, set error status and return false
261+
if(boost::get<CNoDestination>(&newAddress))
261262
{
262-
editStatus = NO_CHANGES;
263+
editStatus = INVALID_ADDRESS;
263264
return false;
264265
}
265-
// Refuse to set invalid address, set error status and return false
266-
else if(!walletModel->validateAddress(value.toString()))
266+
// Do nothing, if old address == new address
267+
else if(newAddress == curAddress)
267268
{
268-
editStatus = INVALID_ADDRESS;
269+
editStatus = NO_CHANGES;
269270
return false;
270271
}
271272
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
272273
// to paste an existing address over another address (with a different label)
273-
else if(wallet->mapAddressBook.count(CBitcoinAddress(value.toString().toStdString()).Get()))
274+
else if(wallet->mapAddressBook.count(newAddress))
274275
{
275276
editStatus = DUPLICATE_ADDRESS;
276277
return false;
277278
}
278279
// Double-check that we're not overwriting a receiving address
279280
else if(rec->type == AddressTableEntry::Sending)
280281
{
281-
{
282-
LOCK(wallet->cs_wallet);
283-
// Remove old entry
284-
wallet->DelAddressBook(CBitcoinAddress(rec->address.toStdString()).Get());
285-
// Add new entry with new address
286-
wallet->SetAddressBook(CBitcoinAddress(value.toString().toStdString()).Get(), rec->label.toStdString(), strPurpose);
287-
}
282+
// Remove old entry
283+
wallet->DelAddressBook(curAddress);
284+
// Add new entry with new address
285+
wallet->SetAddressBook(newAddress, rec->label.toStdString(), strPurpose);
288286
}
289-
break;
290287
}
291288
return true;
292289
}

src/qt/paymentserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
548548
else {
549549
CPubKey newKey;
550550
if (wallet->GetKeyFromPool(newKey)) {
551+
LOCK(wallet->cs_wallet); // SetAddressBook
551552
CKeyID keyID = newKey.GetID();
552553
wallet->SetAddressBook(keyID, strAccount, "refund");
553554

src/qt/walletmodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins)
502502
std::vector<COutput> vCoins;
503503
wallet->AvailableCoins(vCoins);
504504

505+
LOCK(wallet->cs_wallet); // ListLockedCoins, mapWallet
505506
std::vector<COutPoint> vLockedCoins;
506507
wallet->ListLockedCoins(vLockedCoins);
507508

@@ -531,20 +532,24 @@ void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins)
531532

532533
bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const
533534
{
535+
LOCK(wallet->cs_wallet);
534536
return wallet->IsLockedCoin(hash, n);
535537
}
536538

537539
void WalletModel::lockCoin(COutPoint& output)
538540
{
541+
LOCK(wallet->cs_wallet);
539542
wallet->LockCoin(output);
540543
}
541544

542545
void WalletModel::unlockCoin(COutPoint& output)
543546
{
547+
LOCK(wallet->cs_wallet);
544548
wallet->UnlockCoin(output);
545549
}
546550

547551
void WalletModel::listLockedCoins(std::vector<COutPoint>& vOutpts)
548552
{
553+
LOCK(wallet->cs_wallet);
549554
wallet->ListLockedCoins(vOutpts);
550555
}

0 commit comments

Comments
 (0)