summaryrefslogtreecommitdiff
path: root/ArmPlatformPkg
diff options
context:
space:
mode:
authorBrendan Jackman <brendan.jackman@arm.com>2014-05-08 15:03:05 +0000
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>2014-05-08 15:03:05 +0000
commit35d3b52ddd168318892f8598611e6544b3f5a545 (patch)
tree77a48f5c85a64ec5c0789311a6f3246fc1b5ac9d /ArmPlatformPkg
parenta9185e76185f045f5f64919f8ae165f3eb2f0dd6 (diff)
ArmPlatformPkg/BootMonFs: Fix permission check in SetFileInfo
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Brendan Jackman <brendan.jackman@arm.com> Reviewed-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15513 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ArmPlatformPkg')
-rw-r--r--ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c
index 773490e37..bf91bf0e1 100644
--- a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c
+++ b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c
@@ -288,19 +288,21 @@ SetFileName (
}
// If we're changing the file name
- if (AsciiStrCmp (FileNameAscii, File->HwDescription.Footer.Filename)) {
- // Check a file with that filename doesn't already exist
- if (BootMonGetFileFromAsciiFileName (
- File->Instance,
- File->HwDescription.Footer.Filename,
- &SameFile) != EFI_NOT_FOUND) {
- Status = EFI_ACCESS_DENIED;
- } else {
- AsciiStrCpy (FileNameAscii, File->HwDescription.Footer.Filename);
- Status = EFI_SUCCESS;
- }
+ if (AsciiStrCmp (FileNameAscii, File->HwDescription.Footer.Filename) == 0) {
+ // No change to filename.
+ Status = EFI_SUCCESS;
+ } else if (!(File->OpenMode & EFI_FILE_MODE_WRITE)) {
+ // You can only change the filename if you open the file for write.
+ Status = EFI_ACCESS_DENIED;
+ } else if (BootMonGetFileFromAsciiFileName (
+ File->Instance,
+ File->HwDescription.Footer.Filename,
+ &SameFile) != EFI_NOT_FOUND) {
+ // A file with that name already exists.
+ Status = EFI_ACCESS_DENIED;
} else {
- // No change to filename
+ // OK, change the filename.
+ AsciiStrCpy (FileNameAscii, File->HwDescription.Footer.Filename);
Status = EFI_SUCCESS;
}
@@ -316,7 +318,7 @@ EFI_STATUS
SetFileSize (
IN BOOTMON_FS_INSTANCE *Instance,
IN BOOTMON_FS_FILE *BootMonFsFile,
- IN UINTN Size
+ IN UINTN NewSize
)
{
UINT64 StoredPosition;
@@ -324,6 +326,13 @@ SetFileSize (
EFI_FILE_PROTOCOL *File;
CHAR8 Buffer;
UINTN BufferSize;
+ UINT32 OldSize;
+
+ OldSize = BootMonFsFile->HwDescription.Region[0].Size;
+
+ if (OldSize == NewSize) {
+ return EFI_SUCCESS;
+ }
Buffer = 0;
BufferSize = sizeof (Buffer);
@@ -334,8 +343,8 @@ SetFileSize (
return EFI_ACCESS_DENIED;
}
- if (Size <= BootMonFsFile->HwDescription.Region[0].Size) {
- BootMonFsFile->HwDescription.Region[0].Size = Size;
+ if (NewSize <= OldSize) {
+ OldSize = NewSize;
} else {
// Increasing a file's size is potentially complicated as it may require
// moving the image description on media. The simplest way to do it is to
@@ -348,7 +357,7 @@ SetFileSize (
return Status;
}
- Status = File->SetPosition (File, Size - 1);
+ Status = File->SetPosition (File, NewSize - 1);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -358,7 +367,7 @@ SetFileSize (
}
// Restore saved position
- Status = File->SetPosition (File, Size - 1);
+ Status = File->SetPosition (File, NewSize - 1);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -398,7 +407,7 @@ SetFileInfo (
return EFI_ACCESS_DENIED;
}
- SetFileName (File, Info->FileName);
+ Status = SetFileName (File, Info->FileName);
if (EFI_ERROR (Status)) {
return Status;
}