]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg: Use safe string functions to refine code.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index f82668b60fe0bc3f8a3869168cba9ad814c0408d..5b4c6d3fb7e392468aa1a79b79c193779d865d48 100644 (file)
@@ -1713,8 +1713,8 @@ ShellFindFilePath (
     if (TestPath == NULL) {\r
       return (NULL);\r
     }\r
-    StrnCpy(TestPath, Path, Size/sizeof(CHAR16) - 1);\r
-    StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
+    StrCpyS(TestPath, Size/sizeof(CHAR16), Path);\r
+    StrCatS(TestPath, Size/sizeof(CHAR16), FileName);\r
     Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
     if (!EFI_ERROR(Status)){\r
       if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
@@ -1746,12 +1746,12 @@ ShellFindFilePath (
           *TempChar = CHAR_NULL;\r
         }\r
         if (TestPath[StrLen(TestPath)-1] != L'\\') {\r
-          StrnCat(TestPath, L"\\", Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
+          StrCatS(TestPath, Size/sizeof(CHAR16), L"\\");\r
         }\r
         if (FileName[0] == L'\\') {\r
           FileName++;\r
         }\r
-        StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
+        StrCatS(TestPath, Size/sizeof(CHAR16), FileName);\r
         if (StrStr(Walker, L";") != NULL) {\r
           Walker = StrStr(Walker, L";") + 1;\r
         } else {\r
@@ -1820,9 +1820,9 @@ ShellFindFilePathEx (
     return (NULL);\r
   }\r
   for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension;  TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){\r
-    StrnCpy(TestPath, FileName, Size/sizeof(CHAR16) - 1);\r
+    StrCpyS(TestPath, Size/sizeof(CHAR16), FileName);\r
     if (ExtensionWalker != NULL) {\r
-      StrnCat(TestPath, ExtensionWalker, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
+      StrCatS(TestPath, Size/sizeof(CHAR16), ExtensionWalker);\r
     }\r
     TempChar = StrStr(TestPath, L";");\r
     if (TempChar != NULL) {\r
@@ -2109,10 +2109,19 @@ InternalCommandLineParse (
       CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);\r
       ASSERT(CurrentItemPackage->Value != NULL);\r
       if (ValueSize == 0) {\r
-        StrnCpy(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1);\r
+        StrCpyS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  Argv[LoopCounter]\r
+                  );\r
       } else {\r
-        StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
-        StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+        StrCatS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  L" "\r
+                  );\r
+        StrCatS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  Argv[LoopCounter]\r
+                  );\r
       }\r
       ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
       \r
@@ -2635,14 +2644,14 @@ ShellCopySearchAndReplace(
         FreePool(Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrnCat(NewString, Replace, NewSize/sizeof(CHAR16) - 1 - StrLen(NewString));\r
+      StrCatS(NewString, NewSize/sizeof(CHAR16), Replace);\r
     } else {\r
       Size = StrSize(NewString);\r
       if (Size + sizeof(CHAR16) > NewSize) {\r
         FreePool(Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrnCat(NewString, SourceString, 1);\r
+      StrnCatS(NewString, NewSize/sizeof(CHAR16), SourceString, 1);\r
       SourceString++;\r
     }\r
   }\r
@@ -3254,7 +3263,9 @@ StrnCatGrow (
   if (*Destination == NULL) {\r
     return (NULL);\r
   }\r
-  return StrnCat(*Destination, Source, Count);\r
+  \r
+  StrCatS(*Destination, Count + 1, Source);\r
+  return *Destination;\r
 }\r
 \r
 /**\r