From 6b0af70ccdbc10bd118ce39cd09806624f714830 Mon Sep 17 00:00:00 2001 From: Caio Carvalho Date: Mon, 7 May 2018 22:56:24 -0300 Subject: [PATCH] Avoiding segfault in DeleteOperation and ResizeOperation. --- src/ops/deleteoperation.cpp | 14 ++++++++------ src/ops/resizeoperation.cpp | 28 ++++++++++++++++------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/ops/deleteoperation.cpp b/src/ops/deleteoperation.cpp index 768051c..f0168e4 100644 --- a/src/ops/deleteoperation.cpp +++ b/src/ops/deleteoperation.cpp @@ -128,13 +128,15 @@ bool DeleteOperation::canDelete(const Partition* p, const QList pen } else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { // See if innerFS is LVM - FileSystem *fs = static_cast(&p->fileSystem())->innerFS(); + FileSystem *fs = dynamic_cast(&p->fileSystem())->innerFS(); - if (fs->type() == FileSystem::Type::Lvm2_PV) { - // See if there is a newly created VG targeting this partition - for (Operation *op : qAsConst(pendingOps)) { - if (dynamic_cast(op) && op->targets(*p)) - return false; + if (fs) { + if (fs->type() == FileSystem::Type::Lvm2_PV) { + // See if there is a newly created VG targeting this partition + for (Operation *op : qAsConst(pendingOps)) { + if (dynamic_cast(op) && op->targets(*p)) + return false; + } } } } diff --git a/src/ops/resizeoperation.cpp b/src/ops/resizeoperation.cpp index 57b7361..8c44f7b 100644 --- a/src/ops/resizeoperation.cpp +++ b/src/ops/resizeoperation.cpp @@ -362,13 +362,15 @@ bool ResizeOperation::canShrink(const Partition* p, const QList pen } else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { // See if innerFS is LVM - FileSystem *fs = static_cast(&p->fileSystem())->innerFS(); + FileSystem *fs = dynamic_cast(&p->fileSystem())->innerFS(); - if (fs->type() == FileSystem::Type::Lvm2_PV) { - // See if there is a newly created VG targeting this partition - for (Operation *op : qAsConst(pendingOps)) { - if (dynamic_cast(op) && op->targets(*p)) - return false; + if (fs) { + if (fs->type() == FileSystem::Type::Lvm2_PV) { + // See if there is a newly created VG targeting this partition + for (Operation *op : qAsConst(pendingOps)) { + if (dynamic_cast(op) && op->targets(*p)) + return false; + } } } } @@ -404,13 +406,15 @@ bool ResizeOperation::canMove(const Partition* p, const QList pendi } else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { // See if innerFS is LVM - FileSystem *fs = static_cast(&p->fileSystem())->innerFS(); + FileSystem *fs = dynamic_cast(&p->fileSystem())->innerFS(); - if (fs->type() == FileSystem::Type::Lvm2_PV) { - // See if there is a newly created VG targeting this partition - for (Operation *op : qAsConst(pendingOps)) { - if (dynamic_cast(op) && op->targets(*p)) - return false; + if (fs) { + if (fs->type() == FileSystem::Type::Lvm2_PV) { + // See if there is a newly created VG targeting this partition + for (Operation *op : qAsConst(pendingOps)) { + if (dynamic_cast(op) && op->targets(*p)) + return false; + } } } }