]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/BootMonFs: Fix permission check in SetFileInfo
authorBrendan Jackman <brendan.jackman@arm.com>
Thu, 8 May 2014 15:03:05 +0000 (15:03 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 8 May 2014 15:03:05 +0000 (15:03 +0000)
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

ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c

index 773490e37a3aaff425c4557ca99f41d2763b038c..bf91bf0e1a86f0ef3980ee49210e97dd06199a49 100644 (file)
@@ -288,19 +288,21 @@ SetFileName (
   }\r
 \r
   // If we're changing the file name\r
-  if (AsciiStrCmp (FileNameAscii, File->HwDescription.Footer.Filename)) {\r
-    // Check a file with that filename doesn't already exist\r
-    if (BootMonGetFileFromAsciiFileName (\r
-          File->Instance,\r
-          File->HwDescription.Footer.Filename,\r
-          &SameFile) != EFI_NOT_FOUND) {\r
-      Status = EFI_ACCESS_DENIED;\r
-    } else {\r
-      AsciiStrCpy (FileNameAscii, File->HwDescription.Footer.Filename);\r
-      Status = EFI_SUCCESS;\r
-    }\r
+  if (AsciiStrCmp (FileNameAscii, File->HwDescription.Footer.Filename) == 0) {\r
+    // No change to filename.\r
+    Status = EFI_SUCCESS;\r
+  } else if (!(File->OpenMode & EFI_FILE_MODE_WRITE)) {\r
+    // You can only change the filename if you open the file for write.\r
+    Status = EFI_ACCESS_DENIED;\r
+  } else if (BootMonGetFileFromAsciiFileName (\r
+                File->Instance,\r
+                File->HwDescription.Footer.Filename,\r
+                &SameFile) != EFI_NOT_FOUND) {\r
+    // A file with that name already exists.\r
+    Status = EFI_ACCESS_DENIED;\r
   } else {\r
-    // No change to filename\r
+    // OK, change the filename.\r
+    AsciiStrCpy (FileNameAscii, File->HwDescription.Footer.Filename);\r
     Status = EFI_SUCCESS;\r
   }\r
 \r
@@ -316,7 +318,7 @@ EFI_STATUS
 SetFileSize (\r
   IN BOOTMON_FS_INSTANCE *Instance,\r
   IN BOOTMON_FS_FILE     *BootMonFsFile,\r
-  IN UINTN               Size\r
+  IN UINTN                NewSize\r
   )\r
 {\r
   UINT64             StoredPosition;\r
@@ -324,6 +326,13 @@ SetFileSize (
   EFI_FILE_PROTOCOL *File;\r
   CHAR8              Buffer;\r
   UINTN              BufferSize;\r
+  UINT32             OldSize;\r
+\r
+  OldSize = BootMonFsFile->HwDescription.Region[0].Size;\r
+\r
+  if (OldSize == NewSize) {\r
+    return EFI_SUCCESS;\r
+  }\r
 \r
   Buffer = 0;\r
   BufferSize = sizeof (Buffer);\r
@@ -334,8 +343,8 @@ SetFileSize (
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
-  if (Size <= BootMonFsFile->HwDescription.Region[0].Size) {\r
-    BootMonFsFile->HwDescription.Region[0].Size = Size;\r
+  if (NewSize <= OldSize) {\r
+    OldSize = NewSize;\r
   } else {\r
     // Increasing a file's size is potentially complicated as it may require\r
     // moving the image description on media. The simplest way to do it is to\r
@@ -348,7 +357,7 @@ SetFileSize (
       return Status;\r
     }\r
 \r
-    Status = File->SetPosition (File, Size - 1);\r
+    Status = File->SetPosition (File, NewSize - 1);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -358,7 +367,7 @@ SetFileSize (
     }\r
 \r
     // Restore saved position\r
-    Status = File->SetPosition (File, Size - 1);\r
+    Status = File->SetPosition (File, NewSize - 1);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -398,7 +407,7 @@ SetFileInfo (
       return EFI_ACCESS_DENIED;\r
     }\r
 \r
-    SetFileName (File, Info->FileName);\r
+    Status = SetFileName (File, Info->FileName);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r