Skip to content

Commit 4757e92

Browse files
committed
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.
1 parent 7aedb91 commit 4757e92

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-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
}

0 commit comments

Comments
 (0)