]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/EfiFileLib: eliminate deprecated string function calls
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 24 Oct 2016 17:31:53 +0000 (18:31 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 28 Oct 2016 14:54:00 +0000 (15:54 +0100)
Get rid of calls to unsafe string functions. These are deprecated and may
be removed in the future.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c

index 4d58c830861cb885334e5fcee3b2548613b4a68f..8c38d22f1eb14f142e14ce2fc77db85084887d6f 100644 (file)
@@ -384,9 +384,10 @@ EblFileDevicePath (
 \r
 \r
   if ( *FileName != 0 ) {\r
 \r
 \r
   if ( *FileName != 0 ) {\r
-    AsciiStrToUnicodeStr (FileName, UnicodeFileName);\r
+    AsciiStrToUnicodeStrS (FileName, UnicodeFileName,\r
+      ARRAY_SIZE (UnicodeFileName));\r
   } else {\r
   } else {\r
-    AsciiStrToUnicodeStr ("\\", UnicodeFileName);\r
+    AsciiStrToUnicodeStrS ("\\", UnicodeFileName, ARRAY_SIZE (UnicodeFileName));\r
   }\r
 \r
   Size = StrSize (UnicodeFileName);\r
   }\r
 \r
   Size = StrSize (UnicodeFileName);\r
@@ -589,7 +590,7 @@ EblFvFileDevicePath (
           &AuthenticationStatus\r
           );\r
         if (!EFI_ERROR (Status)) {\r
           &AuthenticationStatus\r
           );\r
         if (!EFI_ERROR (Status)) {\r
-          UnicodeStrToAsciiStr (Section, AsciiSection);\r
+          UnicodeStrToAsciiStrS (Section, AsciiSection, MAX_PATHNAME);\r
           if (AsciiStriCmp (FileName, AsciiSection) == 0) {\r
             FreePool (Section);\r
             break;\r
           if (AsciiStriCmp (FileName, AsciiSection) == 0) {\r
             FreePool (Section);\r
             break;\r
@@ -674,6 +675,7 @@ EfiOpen (
   CHAR8                     *CwdPlusPathName;\r
   UINTN                     Index;\r
   EFI_SECTION_TYPE          ModifiedSectionType;\r
   CHAR8                     *CwdPlusPathName;\r
   UINTN                     Index;\r
   EFI_SECTION_TYPE          ModifiedSectionType;\r
+  UINTN                     AsciiLength;\r
 \r
   EblUpdateDeviceLists ();\r
 \r
 \r
   EblUpdateDeviceLists ();\r
 \r
@@ -706,7 +708,8 @@ EfiOpen (
       }\r
 \r
       // We could add a current working directory concept\r
       }\r
 \r
       // We could add a current working directory concept\r
-      CwdPlusPathName = AllocatePool (AsciiStrSize (gCwd) + AsciiStrSize (PathName));\r
+      AsciiLength = AsciiStrSize (gCwd) + AsciiStrSize (PathName);\r
+      CwdPlusPathName = AllocatePool (AsciiLength);\r
       if (CwdPlusPathName == NULL) {\r
         return NULL;\r
       }\r
       if (CwdPlusPathName == NULL) {\r
         return NULL;\r
       }\r
@@ -723,14 +726,14 @@ EfiOpen (
           }\r
         }\r
       } else {\r
           }\r
         }\r
       } else {\r
-        AsciiStrCpy (CwdPlusPathName, gCwd);\r
+        AsciiStrCpyS (CwdPlusPathName, AsciiLength, gCwd);\r
         StrLen = AsciiStrLen (gCwd);\r
         if ((*PathName != '/') && (*PathName != '\\') && (gCwd[StrLen-1] != '/') && (gCwd[StrLen-1] != '\\')) {\r
         StrLen = AsciiStrLen (gCwd);\r
         if ((*PathName != '/') && (*PathName != '\\') && (gCwd[StrLen-1] != '/') && (gCwd[StrLen-1] != '\\')) {\r
-          AsciiStrCat (CwdPlusPathName, "\\");\r
+          AsciiStrCatS (CwdPlusPathName, AsciiLength, "\\");\r
         }\r
       }\r
 \r
         }\r
       }\r
 \r
-      AsciiStrCat (CwdPlusPathName, PathName);\r
+      AsciiStrCatS (CwdPlusPathName, AsciiLength, PathName);\r
       if (AsciiStrStr (CwdPlusPathName, ":") == NULL) {\r
         // Extra error check to make sure we don't recurse and blow stack\r
         return NULL;\r
       if (AsciiStrStr (CwdPlusPathName, ":") == NULL) {\r
         // Extra error check to make sure we don't recurse and blow stack\r
         return NULL;\r
@@ -745,7 +748,7 @@ EfiOpen (
   }\r
 \r
   File->DeviceName = AllocatePool (StrLen);\r
   }\r
 \r
   File->DeviceName = AllocatePool (StrLen);\r
-  AsciiStrCpy (File->DeviceName, PathName);\r
+  AsciiStrCpyS (File->DeviceName, StrLen, PathName);\r
   File->DeviceName[FileStart - 1] = '\0';\r
   File->FileName = &File->DeviceName[FileStart];\r
   if (File->FileName[0] == '\0') {\r
   File->DeviceName[FileStart - 1] = '\0';\r
   File->FileName = &File->DeviceName[FileStart];\r
   if (File->FileName[0] == '\0') {\r
@@ -1611,7 +1614,7 @@ ExpandPath (
 {\r
   CHAR8   *NewPath;\r
   CHAR8   *Work, *Start, *End;\r
 {\r
   CHAR8   *NewPath;\r
   CHAR8   *Work, *Start, *End;\r
-  UINTN   StrLen;\r
+  UINTN   StrLen, AllocLen;\r
   INTN    i;\r
 \r
   if (Cwd == NULL || Path == NULL) {\r
   INTN    i;\r
 \r
   if (Cwd == NULL || Path == NULL) {\r
@@ -1625,11 +1628,12 @@ ExpandPath (
   }\r
 \r
   StrLen = AsciiStrSize (Path);\r
   }\r
 \r
   StrLen = AsciiStrSize (Path);\r
-  NewPath = AllocatePool (AsciiStrSize (Cwd) + StrLen + 1);\r
+  AllocLen = AsciiStrSize (Cwd) + StrLen + 1;\r
+  NewPath = AllocatePool (AllocLen);\r
   if (NewPath == NULL) {\r
     return NULL;\r
   }\r
   if (NewPath == NULL) {\r
     return NULL;\r
   }\r
-  AsciiStrCpy (NewPath, Cwd);\r
+  AsciiStrCpyS (NewPath, AllocLen, Cwd);\r
 \r
   End = Path + StrLen;\r
   for (Start = Path ;;) {\r
 \r
   End = Path + StrLen;\r
   for (Start = Path ;;) {\r
@@ -1640,7 +1644,7 @@ ExpandPath (
     }\r
 \r
     // append path prior to ..\r
     }\r
 \r
     // append path prior to ..\r
-    AsciiStrnCat (NewPath, Start, Work - Start);\r
+    AsciiStrnCatS (NewPath, AllocLen, Start, Work - Start);\r
     StrLen = AsciiStrLen (NewPath);\r
     for (i = StrLen; i >= 0; i--) {\r
       if (NewPath[i] == ':') {\r
     StrLen = AsciiStrLen (NewPath);\r
     for (i = StrLen; i >= 0; i--) {\r
       if (NewPath[i] == ':') {\r
@@ -1663,7 +1667,7 @@ ExpandPath (
   }\r
 \r
   // Handle the path that remains after the ..\r
   }\r
 \r
   // Handle the path that remains after the ..\r
-  AsciiStrnCat (NewPath, Start, End - Start);\r
+  AsciiStrnCatS (NewPath, AllocLen, Start, End - Start);\r
 \r
   return NewPath;\r
 }\r
 \r
   return NewPath;\r
 }\r
@@ -1686,7 +1690,7 @@ EfiSetCwd (
   )\r
 {\r
   EFI_OPEN_FILE *File;\r
   )\r
 {\r
   EFI_OPEN_FILE *File;\r
-  UINTN         Len;\r
+  UINTN         Len, AllocLen;\r
   CHAR8         *Path;\r
 \r
   if (Cwd == NULL) {\r
   CHAR8         *Path;\r
 \r
   if (Cwd == NULL) {\r
@@ -1729,17 +1733,18 @@ EfiSetCwd (
 \r
   // Use the info returned from EfiOpen as it can add in CWD if needed. So Cwd could be\r
   // relative to the current gCwd or not.\r
 \r
   // Use the info returned from EfiOpen as it can add in CWD if needed. So Cwd could be\r
   // relative to the current gCwd or not.\r
-  gCwd = AllocatePool (AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10);\r
+  AllocLen = AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10;\r
+  gCwd = AllocatePool (AllocLen);\r
   if (gCwd == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   if (gCwd == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  AsciiStrCpy (gCwd, File->DeviceName);\r
+  AsciiStrCpyS (gCwd, AllocLen, File->DeviceName);\r
   if (File->FileName == NULL) {\r
   if (File->FileName == NULL) {\r
-    AsciiStrCat (gCwd, ":\\");\r
+    AsciiStrCatS (gCwd, AllocLen, ":\\");\r
   } else {\r
   } else {\r
-    AsciiStrCat (gCwd, ":");\r
-    AsciiStrCat (gCwd, File->FileName);\r
+    AsciiStrCatS (gCwd, AllocLen, ":");\r
+    AsciiStrCatS (gCwd, AllocLen, File->FileName);\r
   }\r
 \r
 \r
   }\r
 \r
 \r