From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 5510521164C7E for ; Sun, 14 Oct 2018 21:55:27 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Oct 2018 21:55:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,383,1534834800"; d="scan'208";a="78773936" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.9]) by fmsmga008.fm.intel.com with ESMTP; 14 Oct 2018 21:55:26 -0700 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Paulo Alcantara , Ruiyu Ni , Star Zeng Date: Mon, 15 Oct 2018 12:55:16 +0800 Message-Id: <20181015045522.18732-2-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20181015045522.18732-1-hao.a.wu@intel.com> References: <20181015045522.18732-1-hao.a.wu@intel.com> Subject: [PATCH v1 1/7] MdeModulePkg/UdfDxe: Use error handling for memory allocation failure 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: Mon, 15 Oct 2018 04:55:27 -0000 REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1247 For functions DuplicateFid() and DuplicateFe(), this commit will use error handling logic instead of ASSERTs for memory allocation failure. Cc: Paulo Alcantara Cc: Ruiyu Ni Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu --- MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c index ecc172303e..638f31bd82 100644 --- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c +++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c @@ -468,8 +468,6 @@ DuplicateFid ( *NewFileIdentifierDesc = (UDF_FILE_IDENTIFIER_DESCRIPTOR *)AllocateCopyPool ( (UINTN) GetFidDescriptorLength (FileIdentifierDesc), FileIdentifierDesc); - - ASSERT (*NewFileIdentifierDesc != NULL); } /** @@ -490,8 +488,6 @@ DuplicateFe ( ) { *NewFileEntry = AllocateCopyPool (Volume->FileEntrySize, FileEntry); - - ASSERT (*NewFileEntry != NULL); } /** @@ -1370,7 +1366,15 @@ InternalFindFile ( } DuplicateFe (BlockIo, Volume, Parent->FileEntry, &File->FileEntry); + if (File->FileEntry == NULL) { + return EFI_OUT_OF_RESOURCES; + } + DuplicateFid (Parent->FileIdentifierDesc, &File->FileIdentifierDesc); + if (File->FileIdentifierDesc == NULL) { + FreePool (File->FileEntry); + return EFI_OUT_OF_RESOURCES; + } return EFI_SUCCESS; } @@ -1732,9 +1736,20 @@ FindFile ( // We've already a file pointer (Root) for the root directory. Duplicate // its FE/EFE and FID descriptors. // - DuplicateFe (BlockIo, Volume, Root->FileEntry, &File->FileEntry); - DuplicateFid (Root->FileIdentifierDesc, &File->FileIdentifierDesc); Status = EFI_SUCCESS; + DuplicateFe (BlockIo, Volume, Root->FileEntry, &File->FileEntry); + if (File->FileEntry == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + // + // File->FileEntry is not NULL. + // + DuplicateFid (Root->FileIdentifierDesc, &File->FileIdentifierDesc); + if (File->FileIdentifierDesc == NULL) { + FreePool (File->FileEntry); + Status = EFI_OUT_OF_RESOURCES; + } + } } } else { // @@ -1874,6 +1889,9 @@ ReadDirectoryEntry ( } while (FileIdentifierDesc->FileCharacteristics & DELETED_FILE); DuplicateFid (FileIdentifierDesc, FoundFid); + if (*FoundFid == NULL) { + return EFI_OUT_OF_RESOURCES; + } return EFI_SUCCESS; } @@ -2031,8 +2049,18 @@ ResolveSymlink ( // "." (current file). Duplicate both FE/EFE and FID of this file. // DuplicateFe (BlockIo, Volume, PreviousFile.FileEntry, &File->FileEntry); + if (File->FileEntry == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Error_Find_File; + } + DuplicateFid (PreviousFile.FileIdentifierDesc, &File->FileIdentifierDesc); + if (File->FileIdentifierDesc == NULL) { + FreePool (File->FileEntry); + Status = EFI_OUT_OF_RESOURCES; + goto Error_Find_File; + } goto Next_Path_Component; case 5: // -- 2.12.0.windows.1