From 8823938c8f549623135d65443d9117ef8d9add3e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 14 Jun 2017 11:39:53 -0400 Subject: [PATCH] PartitionModule: avoid nullptr crashes Fix up iterator code so that it handles nullptr better. This avoids part of #686. --- src/modules/partition/core/PartitionCoreModule.cpp | 4 ++-- src/modules/partition/core/PartitionIterator.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 7ce67be16..151dce4a4 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -157,9 +157,9 @@ PartitionCoreModule::doInit() // Remove the device which contains / from the list for ( QList< Device* >::iterator it = devices.begin(); it != devices.end(); ) - if ( hasRootPartition( *it ) || + if ( *it && ( hasRootPartition( *it ) || (*it)->deviceNode().startsWith( "/dev/zram") || - isIso9660( *it ) ) + isIso9660( *it ) ) ) it = devices.erase( it ); else ++it; diff --git a/src/modules/partition/core/PartitionIterator.cpp b/src/modules/partition/core/PartitionIterator.cpp index df1a2e4d7..26fa1df8c 100644 --- a/src/modules/partition/core/PartitionIterator.cpp +++ b/src/modules/partition/core/PartitionIterator.cpp @@ -2,6 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -83,6 +84,8 @@ PartitionIterator::operator!=( const PartitionIterator& other ) const PartitionIterator PartitionIterator::begin( Device* device ) { + if ( !device ) + return PartitionIterator( nullptr ); Q_ASSERT(device); PartitionTable* table = device->partitionTable(); if ( !table ) @@ -106,6 +109,8 @@ PartitionIterator::begin( PartitionTable* table ) PartitionIterator PartitionIterator::end( Device* device ) { + if ( !device ) + return PartitionIterator( nullptr ); PartitionTable* table = device->partitionTable(); if ( !table ) return PartitionIterator( nullptr );