Handle operations in files and directories from UDF/ECMA-167 file systems.\r
\r
Copyright (C) 2014-2017 Paulo Alcantara <pcacjr@zytor.com>\r
+ Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
\r
This program and the accompanying materials are licensed and made available\r
under the terms and conditions of the BSD License which accompanies this\r
CleanupFileInformation (&PrivFsData->Root);\r
\r
Error_Find_Root_Dir:\r
- CleanupVolumeInformation (&PrivFsData->Volume);\r
\r
Error_Read_Udf_Volume:\r
Error_Invalid_Params:\r
FileName = TempFileName + 1;\r
}\r
\r
- StrCpyS (NewPrivFileData->FileName, UDF_PATH_LENGTH, FileName);\r
+ StrCpyS (NewPrivFileData->FileName, UDF_FILENAME_LENGTH, FileName);\r
\r
Status = GetFileSize (\r
PrivFsData->BlockIo,\r
&NewPrivFileData->File,\r
&NewPrivFileData->FileSize\r
);\r
- ASSERT_EFI_ERROR (Status);\r
if (EFI_ERROR (Status)) {\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: GetFileSize() fails with status - %r.\n",\r
+ __FUNCTION__, Status\r
+ ));\r
goto Error_Get_File_Size;\r
}\r
\r
\r
goto Done;\r
}\r
+ //\r
+ // After calling function ReadDirectoryEntry(), if 'NewFileIdentifierDesc'\r
+ // is NULL, then the 'Status' must be EFI_OUT_OF_RESOURCES. Hence, if the\r
+ // code reaches here, 'NewFileIdentifierDesc' must be not NULL.\r
+ //\r
+ // The ASSERT here is for addressing a false positive NULL pointer\r
+ // dereference issue raised from static analysis.\r
+ //\r
+ ASSERT (NewFileIdentifierDesc != NULL);\r
\r
if (!IS_FID_PARENT_FILE (NewFileIdentifierDesc)) {\r
break;\r
if (EFI_ERROR (Status)) {\r
goto Error_Find_Fe;\r
}\r
+ ASSERT (NewFileEntryData != NULL);\r
\r
- if (IS_FE_SYMLINK (NewFileEntryData)) {\r
+ if (FE_ICB_FILE_TYPE (NewFileEntryData) == UdfFileEntrySymlink) {\r
Status = ResolveSymlink (\r
BlockIo,\r
DiskIo,\r
FreePool ((VOID *)NewFileEntryData);\r
NewFileEntryData = FoundFile.FileEntry;\r
\r
- Status = GetFileNameFromFid (NewFileIdentifierDesc, FileName);\r
+ Status = GetFileNameFromFid (NewFileIdentifierDesc, ARRAY_SIZE (FileName), FileName);\r
if (EFI_ERROR (Status)) {\r
FreePool ((VOID *)FoundFile.FileIdentifierDesc);\r
goto Error_Get_FileName;\r
FoundFile.FileIdentifierDesc = NewFileIdentifierDesc;\r
FoundFile.FileEntry = NewFileEntryData;\r
\r
- Status = GetFileNameFromFid (FoundFile.FileIdentifierDesc, FileName);\r
+ Status = GetFileNameFromFid (FoundFile.FileIdentifierDesc, ARRAY_SIZE (FileName), FileName);\r
if (EFI_ERROR (Status)) {\r
goto Error_Get_FileName;\r
}\r
PrivFileData->FilePosition++;\r
Status = EFI_SUCCESS;\r
} else if (IS_FID_DELETED_FILE (Parent->FileIdentifierDesc)) {\r
+ //\r
+ // Code should never reach here.\r
+ //\r
+ ASSERT (FALSE);\r
Status = EFI_DEVICE_ERROR;\r
}\r
\r
EFI_TPL OldTpl;\r
EFI_STATUS Status;\r
PRIVATE_UDF_FILE_DATA *PrivFileData;\r
- PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData;\r
\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
\r
\r
PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);\r
\r
- PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (PrivFileData->SimpleFs);\r
-\r
if (!PrivFileData->IsRootDirectory) {\r
CleanupFileInformation (&PrivFileData->File);\r
\r
}\r
}\r
\r
- if (--PrivFsData->OpenFiles == 0) {\r
- CleanupVolumeInformation (&PrivFsData->Volume);\r
- }\r
-\r
FreePool ((VOID *)PrivFileData);\r
\r
Exit:\r
// As per UEFI spec, if the file handle is a directory, then the current file\r
// position has no meaning and the operation is not supported.\r
//\r
- if (IS_FID_DIRECTORY_FILE (&PrivFileData->File.FileIdentifierDesc)) {\r
+ if (IS_FID_DIRECTORY_FILE (PrivFileData->File.FileIdentifierDesc)) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
\r
PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);\r
\r
- FileIdentifierDesc = PrivFileData->File.FileIdentifierDesc;\r
+ FileIdentifierDesc = _FILE (PrivFileData)->FileIdentifierDesc;\r
+ ASSERT (FileIdentifierDesc != NULL);\r
if (IS_FID_DIRECTORY_FILE (FileIdentifierDesc)) {\r
//\r
// If the file handle is a directory, the _only_ position that may be set is\r
/**\r
Get information about a file.\r
\r
+ @attention This is boundary function that may receive untrusted input.\r
+ @attention The input is from FileSystem.\r
+\r
+ The File Set Descriptor is external input, so this routine will do basic\r
+ validation for File Set Descriptor and report status.\r
+\r
@param This Protocol instance pointer.\r
@param InformationType Type of information to return in Buffer.\r
@param BufferSize On input size of buffer, on output amount of data in\r
} else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {\r
String = VolumeLabel;\r
\r
- FileSetDesc = PrivFsData->Volume.FileSetDescs[0];\r
+ FileSetDesc = &PrivFsData->Volume.FileSetDesc;\r
\r
OstaCompressed = &FileSetDesc->LogicalVolumeIdentifier[0];\r
\r
*String = *(UINT8 *)(OstaCompressed + Index) << 8;\r
Index++;\r
} else {\r
+ if (Index > ARRAY_SIZE (VolumeLabel)) {\r
+ return EFI_VOLUME_CORRUPTED;\r
+ }\r
+\r
*String = 0;\r
}\r
\r
if (Index < 128) {\r
- *String |= *(UINT8 *)(OstaCompressed + Index);\r
+ *String |= (CHAR16)(*(UINT8 *)(OstaCompressed + Index));\r
}\r
\r
//\r
String++;\r
}\r
\r
- *String = L'\0';\r
+ Index = ((UINTN)String - (UINTN)VolumeLabel) / sizeof (CHAR16);\r
+ if (Index > ARRAY_SIZE (VolumeLabel) - 1) {\r
+ Index = ARRAY_SIZE (VolumeLabel) - 1;\r
+ }\r
+ VolumeLabel[Index] = L'\0';\r
\r
FileSystemInfoLength = StrSize (VolumeLabel) +\r
sizeof (EFI_FILE_SYSTEM_INFO);\r
}\r
\r
FileSystemInfo = (EFI_FILE_SYSTEM_INFO *)Buffer;\r
- StrCpyS (FileSystemInfo->VolumeLabel, ARRAY_SIZE (VolumeLabel),\r
- VolumeLabel);\r
+ StrCpyS (\r
+ FileSystemInfo->VolumeLabel,\r
+ (*BufferSize - OFFSET_OF (EFI_FILE_SYSTEM_INFO, VolumeLabel)) / sizeof (CHAR16),\r
+ VolumeLabel\r
+ );\r
Status = GetVolumeSize (\r
PrivFsData->BlockIo,\r
PrivFsData->DiskIo,\r
FileSystemInfo->Size = FileSystemInfoLength;\r
FileSystemInfo->ReadOnly = TRUE;\r
FileSystemInfo->BlockSize =\r
- LV_BLOCK_SIZE (&PrivFsData->Volume, UDF_DEFAULT_LV_NUM);\r
+ PrivFsData->Volume.LogicalVolDesc.LogicalBlockSize;\r
FileSystemInfo->VolumeSize = VolumeSize;\r
FileSystemInfo->FreeSpace = FreeSpaceSize;\r
\r
/**\r
Set information about a file.\r
\r
- @param File Protocol instance pointer.\r
+ @param This Protocol instance pointer.\r
@param InformationType Type of information in Buffer.\r
@param BufferSize Size of buffer.\r
@param Buffer The data to write.\r