Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit a819cb1

Browse files
committed
[nemo-storage] Do not accept invalid block devices. Fixes JB#46420
A block device that is dm device must have crypto backing device. Clear partition wait timers when a block is removed. Also destroy block explicitly when block is removed. Previously we started another wait timer when block completed (after all interfaces were checked).
1 parent 70a64d9 commit a819cb1

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/udisks2block.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,11 @@ bool UDisks2::Block::isExternal() const
267267

268268
bool UDisks2::Block::isValid() const
269269
{
270-
return m_interfacePropertyMap.contains(UDISKS2_BLOCK_INTERFACE);
270+
bool hasBlock = m_interfacePropertyMap.contains(UDISKS2_BLOCK_INTERFACE);
271+
if (hasBlock && device().startsWith(QStringLiteral("/dev/dm"))) {
272+
return hasCryptoBackingDevice();
273+
}
274+
return hasBlock;
271275
}
272276

273277
QString UDisks2::Block::idType() const

src/udisks2blockdevices.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ bool BlockDevices::contains(const QString &dbusObjectPath) const
6666

6767
void BlockDevices::remove(const QString &dbusObjectPath)
6868
{
69-
Block *block = m_blockDevices.take(dbusObjectPath);
70-
block->deleteLater();
69+
if (contains(dbusObjectPath)) {
70+
Block *block = m_blockDevices.take(dbusObjectPath);
71+
clearPartitionWait(dbusObjectPath, false);
72+
delete block;
73+
}
7174
}
7275

7376
Block *BlockDevices::device(const QString &dbusObjectPath) const
@@ -189,16 +192,22 @@ void BlockDevices::clearPartitionWait(const QString &dbusObjectPath, bool destro
189192

190193
void BlockDevices::removeInterfaces(const QString &dbusObjectPath, const QStringList &interfaces)
191194
{
192-
if (contains(dbusObjectPath)) {
193-
UDisks2::Block *block = device(dbusObjectPath);
195+
clearPartitionWait(dbusObjectPath, false);
196+
197+
UDisks2::Block *block = device(dbusObjectPath);
198+
if (block) {
194199
if (interfaces.contains(UDISKS2_FILESYSTEM_INTERFACE)) {
195200
block->removeInterface(UDISKS2_FILESYSTEM_INTERFACE);
196201
}
197202
if (interfaces.contains(UDISKS2_ENCRYPTED_INTERFACE)) {
198203
block->removeInterface(UDISKS2_ENCRYPTED_INTERFACE);
199204
}
205+
206+
if (interfaces.contains(UDISKS2_BLOCK_INTERFACE)) {
207+
delete block;
208+
m_blockDevices.remove(dbusObjectPath);
209+
}
200210
}
201-
clearPartitionWait(dbusObjectPath, true);
202211
}
203212

204213
bool BlockDevices::isExternal(const QString &dbusObjectPath)
@@ -210,7 +219,8 @@ bool BlockDevices::isExternal(const QString &dbusObjectPath)
210219
void BlockDevices::blockCompleted()
211220
{
212221
Block *completedBlock = qobject_cast<Block *>(sender());
213-
if (completedBlock->isPartitionTable() || (completedBlock->hasInterface(UDISKS2_BLOCK_INTERFACE) && completedBlock->interfaceCount() == 1)) {
222+
if (completedBlock->isValid() && (completedBlock->isPartitionTable() ||
223+
(completedBlock->hasInterface(UDISKS2_BLOCK_INTERFACE) && completedBlock->interfaceCount() == 1)) ){
214224
qCInfo(lcMemoryCardLog) << "Start waiting for block" << completedBlock->device();
215225
waitPartition(completedBlock);
216226
return;

0 commit comments

Comments
 (0)