]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellManParser.c
ShellPkg: Use safe string functions to refine code.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellManParser.c
index 30470e1987e3c49a79832961a70c7b6bb5d93397..78b8decd832412584732dea1459dffacb010e46a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell MAN file parser.\r
 \r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, 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
@@ -43,8 +43,16 @@ GetManFileName(
   } else {\r
     Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));\r
     if (Buffer != NULL) {\r
-      StrnCpy(Buffer, ManFileName, StrLen(ManFileName));\r
-      StrnCat(Buffer, L".man", 4);\r
+      StrnCpyS( Buffer, \r
+                (StrSize(ManFileName) + 4*sizeof(CHAR16))/sizeof(CHAR16), \r
+                ManFileName, \r
+                StrLen(ManFileName)\r
+                );\r
+      StrnCatS( Buffer, \r
+                (StrSize(ManFileName) + 4*sizeof(CHAR16))/sizeof(CHAR16),\r
+                L".man", \r
+                4\r
+                );\r
     }\r
   }\r
   return (Buffer);\r
@@ -392,9 +400,9 @@ ManBufferFindTitleSection(
   if (TitleString == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  StrnCpy(TitleString, StartString, TitleLength/sizeof(CHAR16) - 1);\r
-  StrnCat(TitleString, Command,     TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString));\r
-  StrnCat(TitleString, EndString,   TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString));\r
+  StrCpyS(TitleString, TitleLength/sizeof(CHAR16), StartString);\r
+  StrCatS(TitleString, TitleLength/sizeof(CHAR16), Command);\r
+  StrCatS(TitleString, TitleLength/sizeof(CHAR16), EndString);\r
 \r
   CurrentLocation = StrStr(*Buffer, TitleString);\r
   if (CurrentLocation == NULL){\r
@@ -418,7 +426,7 @@ ManBufferFindTitleSection(
         if (*BriefDesc == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
         } else {\r
-          StrnCpy(*BriefDesc, CurrentLocation, TitleEnd-CurrentLocation);\r
+          StrnCpyS(*BriefDesc, (*BriefSize)/sizeof(CHAR16), CurrentLocation, TitleEnd-CurrentLocation);\r
         }\r
       }\r
 \r
@@ -495,8 +503,8 @@ ManFileFindTitleSection(
     FreePool(ReadLine);\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  StrnCpy(TitleString, L".TH ", TitleSize/sizeof(CHAR16) - 1);\r
-  StrnCat(TitleString, Command, TitleSize/sizeof(CHAR16) - 1 - StrLen(TitleString));\r
+  StrCpyS(TitleString, TitleSize/sizeof(CHAR16), L".TH ");\r
+  StrCatS(TitleString, TitleSize/sizeof(CHAR16), Command);\r
 \r
   TitleLen = StrLen(TitleString);\r
   for (;!ShellFileHandleEof(Handle);Size = 1024) {\r
@@ -532,7 +540,7 @@ ManFileFindTitleSection(
           Status = EFI_OUT_OF_RESOURCES;\r
           break;\r
         }\r
-        StrnCpy(*BriefDesc, TitleEnd, (*BriefSize)/sizeof(CHAR16) - 1);\r
+        StrCpyS(*BriefDesc, (*BriefSize)/sizeof(CHAR16), TitleEnd);\r
       }\r
       break;\r
     }\r