From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 041D62194D3AE for ; Tue, 16 Oct 2018 01:14:48 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2018 01:14:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,387,1534834800"; d="scan'208";a="272788277" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.9]) by fmsmga006.fm.intel.com with ESMTP; 16 Oct 2018 01:14:48 -0700 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Ruiyu Ni Date: Tue, 16 Oct 2018 16:14:39 +0800 Message-Id: <20181016081442.24236-4-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20181016081442.24236-1-hao.a.wu@intel.com> References: <20181016081442.24236-1-hao.a.wu@intel.com> Subject: [PATCH v2 3/6] MdeModulePkg/UdfDxe: Use error handling when fail to return LSN X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Oct 2018 08:14:49 -0000 REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1248 This commit will refine the ASSERTs in function GetLongAdLsn() and GetAllocationDescriptorLsn() when the logical sector number cannot be returned due to unrecognized media format. Error handling logic will be used for those ASSERTs. Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Paulo Alcantara Reviewed-by: Star Zeng --- MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c | 101 +++++++++++++------- 1 file changed, 69 insertions(+), 32 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c index 8b58cc9eb1..1400846bf1 100644 --- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c +++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c @@ -271,26 +271,39 @@ GetPdFromLongAd ( /** Return logical sector number of a given Long Allocation Descriptor. - @param[in] Volume Volume information pointer. - @param[in] LongAd Long Allocation Descriptor pointer. + @param[in] Volume Volume information pointer. + @param[in] LongAd Long Allocation Descriptor pointer. + @param[out] Lsn Logical sector number pointer. - @return The logical sector number of a given Long Allocation Descriptor. + @retval EFI_SUCCESS Logical sector number successfully returned. + @retval EFI_UNSUPPORTED Logical sector number is not returned due to + unrecognized format. **/ -UINT64 +EFI_STATUS GetLongAdLsn ( - IN UDF_VOLUME_INFO *Volume, - IN UDF_LONG_ALLOCATION_DESCRIPTOR *LongAd + IN UDF_VOLUME_INFO *Volume, + IN UDF_LONG_ALLOCATION_DESCRIPTOR *LongAd, + OUT UINT64 *Lsn ) { UDF_PARTITION_DESCRIPTOR *PartitionDesc; PartitionDesc = GetPdFromLongAd (Volume, LongAd); - ASSERT (PartitionDesc != NULL); + if (PartitionDesc == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Fail to get the Partition Descriptor from the given Long Allocation Descriptor.\n", + __FUNCTION__ + )); + return EFI_UNSUPPORTED; + } - return (UINT64)PartitionDesc->PartitionStartingLocation - - Volume->MainVdsStartLocation + - LongAd->ExtentLocation.LogicalBlockNumber; + *Lsn = (UINT64)PartitionDesc->PartitionStartingLocation - + Volume->MainVdsStartLocation + + LongAd->ExtentLocation.LogicalBlockNumber; + + return EFI_SUCCESS; } /** @@ -342,7 +355,10 @@ FindFileSetDescriptor ( UDF_DESCRIPTOR_TAG *DescriptorTag; LogicalVolDesc = &Volume->LogicalVolDesc; - Lsn = GetLongAdLsn (Volume, &LogicalVolDesc->LogicalVolumeContentsUse); + Status = GetLongAdLsn (Volume, &LogicalVolDesc->LogicalVolumeContentsUse, &Lsn); + if (EFI_ERROR (Status)) { + return Status; + } // // As per UDF 2.60 specification: @@ -732,34 +748,43 @@ GetAllocationDescriptor ( @param[in] Volume Volume information pointer. @param[in] ParentIcb Long Allocation Descriptor pointer. @param[in] Ad Allocation Descriptor pointer. + @param[out] Lsn Logical sector number pointer. - @return The logical sector number of the given Allocation Descriptor. + @retval EFI_SUCCESS Logical sector number of the given Allocation + Descriptor successfully returned. + @retval EFI_UNSUPPORTED Logical sector number of the given Allocation + Descriptor is not returned due to unrecognized + format. **/ -UINT64 +EFI_STATUS GetAllocationDescriptorLsn ( - IN UDF_FE_RECORDING_FLAGS RecordingFlags, - IN UDF_VOLUME_INFO *Volume, - IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, - IN VOID *Ad + IN UDF_FE_RECORDING_FLAGS RecordingFlags, + IN UDF_VOLUME_INFO *Volume, + IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, + IN VOID *Ad, + OUT UINT64 *Lsn ) { UDF_PARTITION_DESCRIPTOR *PartitionDesc; if (RecordingFlags == LongAdsSequence) { - return GetLongAdLsn (Volume, (UDF_LONG_ALLOCATION_DESCRIPTOR *)Ad); + return GetLongAdLsn (Volume, (UDF_LONG_ALLOCATION_DESCRIPTOR *)Ad, Lsn); } else if (RecordingFlags == ShortAdsSequence) { PartitionDesc = GetPdFromLongAd (Volume, ParentIcb); - ASSERT (PartitionDesc != NULL); + if (PartitionDesc == NULL) { + return EFI_UNSUPPORTED; + } - return GetShortAdLsn ( - Volume, - PartitionDesc, - (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad - ); + *Lsn = GetShortAdLsn ( + Volume, + PartitionDesc, + (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad + ); + return EFI_SUCCESS; } - return 0; + return EFI_UNSUPPORTED; } /** @@ -804,10 +829,14 @@ GetAedAdsOffset ( UDF_DESCRIPTOR_TAG *DescriptorTag; ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad); - Lsn = GetAllocationDescriptorLsn (RecordingFlags, + Status = GetAllocationDescriptorLsn (RecordingFlags, Volume, ParentIcb, - Ad); + Ad, + &Lsn); + if (EFI_ERROR (Status)) { + return Status; + } Data = AllocatePool (ExtentLength); if (Data == NULL) { @@ -1156,10 +1185,14 @@ ReadFile ( ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad); - Lsn = GetAllocationDescriptorLsn (RecordingFlags, - Volume, - ParentIcb, - Ad); + Status = GetAllocationDescriptorLsn (RecordingFlags, + Volume, + ParentIcb, + Ad, + &Lsn); + if (EFI_ERROR (Status)) { + goto Done; + } switch (ReadFileInfo->Flags) { case ReadFileGetFileSize: @@ -1630,7 +1663,11 @@ FindFileEntry ( UDF_DESCRIPTOR_TAG *DescriptorTag; VOID *ReadBuffer; - Lsn = GetLongAdLsn (Volume, Icb); + Status = GetLongAdLsn (Volume, Icb, &Lsn); + if (EFI_ERROR (Status)) { + return Status; + } + LogicalBlockSize = Volume->LogicalVolDesc.LogicalBlockSize; ReadBuffer = AllocateZeroPool (Volume->FileEntrySize); -- 2.12.0.windows.1