qt: add missing cs_wallet lock in AddressTableModel::setData
duplicate check in AddressTableModel::setData accesses wallet data structure as well as SetAddressBook without proper LOCK, fix this.
This commit is contained in:
parent
7aedb91476
commit
4757e92318
1 changed files with 18 additions and 21 deletions
|
@ -244,33 +244,34 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
|
|||
|
||||
if(role == Qt::EditRole)
|
||||
{
|
||||
switch(index.column())
|
||||
LOCK(wallet->cs_wallet); /* For SetAddressBook / DelAddressBook */
|
||||
CTxDestination curAddress = CBitcoinAddress(rec->address.toStdString()).Get();
|
||||
if(index.column() == Label)
|
||||
{
|
||||
case Label:
|
||||
// Do nothing, if old label == new label
|
||||
if(rec->label == value.toString())
|
||||
{
|
||||
editStatus = NO_CHANGES;
|
||||
return false;
|
||||
}
|
||||
wallet->SetAddressBook(CBitcoinAddress(rec->address.toStdString()).Get(), value.toString().toStdString(), strPurpose);
|
||||
break;
|
||||
case Address:
|
||||
// Do nothing, if old address == new address
|
||||
if(CBitcoinAddress(rec->address.toStdString()) == CBitcoinAddress(value.toString().toStdString()))
|
||||
{
|
||||
editStatus = NO_CHANGES;
|
||||
return false;
|
||||
}
|
||||
wallet->SetAddressBook(curAddress, value.toString().toStdString(), strPurpose);
|
||||
} else if(index.column() == Address) {
|
||||
CTxDestination newAddress = CBitcoinAddress(value.toString().toStdString()).Get();
|
||||
// Refuse to set invalid address, set error status and return false
|
||||
else if(!walletModel->validateAddress(value.toString()))
|
||||
if(boost::get<CNoDestination>(&newAddress))
|
||||
{
|
||||
editStatus = INVALID_ADDRESS;
|
||||
return false;
|
||||
}
|
||||
// Do nothing, if old address == new address
|
||||
else if(newAddress == curAddress)
|
||||
{
|
||||
editStatus = NO_CHANGES;
|
||||
return false;
|
||||
}
|
||||
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
|
||||
// to paste an existing address over another address (with a different label)
|
||||
else if(wallet->mapAddressBook.count(CBitcoinAddress(value.toString().toStdString()).Get()))
|
||||
else if(wallet->mapAddressBook.count(newAddress))
|
||||
{
|
||||
editStatus = DUPLICATE_ADDRESS;
|
||||
return false;
|
||||
|
@ -278,16 +279,12 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
|
|||
// Double-check that we're not overwriting a receiving address
|
||||
else if(rec->type == AddressTableEntry::Sending)
|
||||
{
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
// Remove old entry
|
||||
wallet->DelAddressBook(CBitcoinAddress(rec->address.toStdString()).Get());
|
||||
wallet->DelAddressBook(curAddress);
|
||||
// Add new entry with new address
|
||||
wallet->SetAddressBook(CBitcoinAddress(value.toString().toStdString()).Get(), rec->label.toStdString(), strPurpose);
|
||||
wallet->SetAddressBook(newAddress, rec->label.toStdString(), strPurpose);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue