]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
MdePkg/BaseSafeIntLib: fix undefined behavior in SafeInt64Add()
[mirror_edk2.git] / MdePkg / Library / UefiFileHandleLib / UefiFileHandleLib.c
index a31d12b862d760cad6bd44f3e96c36dbb134e344..57aad77bc13542ce7828853a1500f75e79a43ab3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to EFI_FILE_HANDLE functionality.\r
 \r
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -231,7 +231,7 @@ FileHandleWrite(
 \r
 @param FileHandle               the file handle to close.\r
 \r
-@retval EFI_SUCCESS             the file handle was closed sucessfully.\r
+@retval EFI_SUCCESS             the file handle was closed successfully.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -261,7 +261,7 @@ FileHandleClose (
 \r
   @param FileHandle             the file handle to delete\r
 \r
-  @retval EFI_SUCCESS           the file was closed sucessfully\r
+  @retval EFI_SUCCESS           the file was closed successfully\r
   @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
                                 deleted\r
   @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
@@ -297,9 +297,9 @@ FileHandleDelete (
   has the effect of starting the read process of the directory entries over.\r
 \r
   @param FileHandle             The file handle on which the position is being set\r
-  @param Position               Byte position from begining of file\r
+  @param Position               Byte position from beginning of file\r
 \r
-  @retval EFI_SUCCESS           Operation completed sucessfully.\r
+  @retval EFI_SUCCESS           Operation completed successfully.\r
   @retval EFI_UNSUPPORTED       the seek request for non-zero is not valid on\r
                                 directories.\r
   @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
@@ -330,9 +330,9 @@ FileHandleSetPosition (
   if FileHandle is a directory.\r
 \r
   @param FileHandle             The open file handle on which to get the position.\r
-  @param Position               Byte position from begining of file.\r
+  @param Position               Byte position from beginning of file.\r
 \r
-  @retval EFI_SUCCESS           the operation completed sucessfully.\r
+  @retval EFI_SUCCESS           the operation completed successfully.\r
   @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
   @retval EFI_UNSUPPORTED       the request is not valid on directories.\r
 **/\r
@@ -489,7 +489,7 @@ FileHandleFindFirstFile (
   }\r
 \r
   //\r
-  // reset to the begining of the directory\r
+  // reset to the beginning of the directory\r
   //\r
   Status = FileHandleSetPosition(DirHandle, 0);\r
   if (EFI_ERROR(Status)) {\r
@@ -581,7 +581,7 @@ FileHandleFindNextFile(
   @param[in] FileHandle         The file handle from which size is retrieved.\r
   @param[out] Size              The pointer to size.\r
 \r
-  @retval EFI_SUCCESS           Operation was completed sucessfully.\r
+  @retval EFI_SUCCESS           Operation was completed successfully.\r
   @retval EFI_DEVICE_ERROR      Cannot access the file.\r
   @retval EFI_INVALID_PARAMETER FileHandle is NULL.\r
                                 Size is NULL.\r
@@ -769,7 +769,9 @@ StrnCatGrowLeft (
 \r
 /**\r
   Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the\r
-  directory 'stack'.\r
+  directory 'stack'. If the file is a directory, then append the '\' char at the \r
+  end of name string. If it's not a directory, then the last '\' should not be \r
+  added.\r
 \r
   if Handle is NULL, return EFI_INVALID_PARAMETER\r
 \r
@@ -819,7 +821,7 @@ FileHandleGetFileName (
         break;\r
       } else {\r
         //\r
-        // We got info... do we have a name? if yes preceed the current path with it...\r
+        // We got info... do we have a name? if yes precede the current path with it...\r
         //\r
         if (StrLen (FileInfo->FileName) == 0) {\r
           if (*FullFileName == NULL) {\r
@@ -856,6 +858,14 @@ FileHandleGetFileName (
     *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
   }\r
 \r
+  if (*FullFileName != NULL && \r
+      (*FullFileName)[StrLen(*FullFileName) - 1] == L'\\' && \r
+      StrLen(*FullFileName) > 1 &&\r
+      FileHandleIsDirectory(Handle) == EFI_NOT_FOUND\r
+     ) {\r
+    (*FullFileName)[StrLen(*FullFileName) - 1] = CHAR_NULL;\r
+  }\r
+\r
   if (CurrentHandle != NULL) {\r
     CurrentHandle->Close (CurrentHandle);\r
   }\r
@@ -1069,6 +1079,7 @@ FileHandleWriteLine(
   EFI_STATUS  Status;\r
   CHAR16      CharBuffer;\r
   UINTN       Size;\r
+  UINTN       Index;\r
   UINTN       CharSize;\r
   UINT64      FileSize;\r
   UINT64      OriginalFilePosition;\r
@@ -1125,7 +1136,13 @@ FileHandleWriteLine(
     if (AsciiBuffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    UnicodeStrToAsciiStr (Buffer, AsciiBuffer);\r
+    UnicodeStrToAsciiStrS (Buffer, AsciiBuffer, Size);\r
+    for (Index = 0; Index < Size; Index++) {\r
+      if ((AsciiBuffer[Index] & BIT7) != 0) {\r
+        FreePool(AsciiBuffer);\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+    }\r
     \r
     Size = AsciiStrSize(AsciiBuffer) - sizeof(CHAR8);\r
     Status = FileHandleWrite(Handle, &Size, AsciiBuffer);\r
@@ -1164,7 +1181,7 @@ FileHandleWriteLine(
   @param[in] Format   the format argument (see printlib for format specifier)\r
   @param[in] ...      the variable arguments for the format\r
 \r
-  @retval EFI_SUCCESS the operation was sucessful\r
+  @retval EFI_SUCCESS the operation was successful\r
   @return other       a return value from FileHandleWriteLine\r
 \r
   @sa FileHandleWriteLine\r