From 7c2135591ba90958b5c8d92a2a5ef8a930c9ee28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 28 Dec 2018 16:01:31 +0100 Subject: [PATCH] KDiskDeviceManager: Ignore invalid partitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Partitions with negative offsets were already ignored, now also ignore those with an invalid size of block size, too. Change-Id: I128e38773933f8eadded0977a957f607363cccbe Reviewed-on: https://review.haiku-os.org/c/805 Reviewed-by: Axel Dörfler --- .../KDiskDeviceManager.cpp | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp b/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp index 74b11d9223..01aa97cc89 100644 --- a/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp +++ b/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp @@ -1,8 +1,7 @@ /* - * Copyright 2004-2017, Haiku, Inc. All rights reserved. - * Copyright 2003-2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved. - * - * Distributed under the terms of the MIT License. + * Copyright 2004-2018, Haiku, Inc. + * Copyright 2003-2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. + * All rights reserved. Distributed under the terms of the MIT License. */ @@ -1373,13 +1372,19 @@ KDiskDeviceManager::_ScanPartition(KPartition* partition, return B_OK; } - // This happens with some copy protected CDs. Just ignore the partition... - if (partition->Offset() < 0) + KPath partitionPath; + partition->GetPath(&partitionPath); + + // This happens with some copy protected CDs or eventually other issues. + // Just ignore the partition... + if (partition->Offset() < 0 || partition->BlockSize() == 0 + || partition->Size() <= 0) { + OUT("Partition %s has invalid parameters, ignoring it.\n", + partitionPath.Path()); return B_BAD_DATA; + } DBG( - KPath partitionPath; - partition->GetPath(&partitionPath); OUT("KDiskDeviceManager::_ScanPartition(%s)\n", partitionPath.Path()); ) @@ -1414,7 +1419,7 @@ KDiskDeviceManager::_ScanPartition(KPartition* partition, if (priority >= 0 && priority > bestPriority) { // new best disk system - if (bestDiskSystem) { + if (bestDiskSystem != NULL) { bestDiskSystem->FreeIdentifyCookie(partition, bestCookie); bestDiskSystem->Unload(); } @@ -1431,7 +1436,7 @@ KDiskDeviceManager::_ScanPartition(KPartition* partition, } // now, if we have found a disk system, let it scan the partition - if (bestDiskSystem) { + if (bestDiskSystem != NULL) { DBG(OUT(" scanning with: %s\n", bestDiskSystem->Name())); error = bestDiskSystem->Scan(partition, bestCookie); bestDiskSystem->FreeIdentifyCookie(partition, bestCookie);