]> git.proxmox.com Git - mirror_edk2.git/commitdiff
FatPkg EnhancedFatDxe: Use safe string functions
authorHao Wu <hao.a.wu@intel.com>
Mon, 6 Jul 2015 01:41:45 +0000 (01:41 +0000)
committerJordan Justen <jordan.l.justen@intel.com>
Thu, 7 Apr 2016 06:22:43 +0000 (23:22 -0700)
Unsafe string functions are replaced with safe ones.

Safe string functions will assert if DestMax is not greater than
StrnLenS(Source, DestMax). Therefore, additional assert for checking the
size of source and destination buffers can be removed.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
(based on FatPkg commit 2cb92b4f19b096daf133d6501afa13e5a85062c5)

[jordan.l.justen@intel.com: Use script to relicense to 2-clause BSD]
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Acked-by: Mark Doran <mark.doran@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
FatPkg/EnhancedFatDxe/DirectoryManage.c
FatPkg/EnhancedFatDxe/Fat.h
FatPkg/EnhancedFatDxe/FileName.c
FatPkg/EnhancedFatDxe/Hash.c

index 116f87a4c2b1066a6be8ddcd8b3c46960011c74d..91e7599e272258e465f485c35416af0f33c16208 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution. The full text of the license may be found at\r
@@ -116,7 +116,15 @@ Returns:
     // Write LFN directory entry\r
     //\r
     SetMem (LfnBuffer, sizeof (CHAR16) * LFN_CHAR_TOTAL * EntryCount, 0xff);\r
-    StrCpy (LfnBuffer, DirEnt->FileString);\r
+    Status = StrCpyS (\r
+               LfnBuffer,\r
+               sizeof (LfnBuffer) / sizeof (LfnBuffer[0]),\r
+               DirEnt->FileString\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
     LfnBufferPointer    = LfnBuffer;\r
     LfnEntry.Attributes = FAT_ATTRIBUTE_LFN;\r
     LfnEntry.Type       = 0;\r
@@ -349,7 +357,11 @@ Returns:
     // Fail to get the long file name from long file name entry,\r
     // get the file name from short name\r
     //\r
-    FatGetFileNameViaCaseFlag (DirEnt, LfnBuffer);\r
+    FatGetFileNameViaCaseFlag (\r
+      DirEnt,\r
+      LfnBuffer,\r
+      sizeof (LfnBuffer) / sizeof (LfnBuffer[0])\r
+      );\r
   }\r
 \r
   DirEnt->FileString = AllocateCopyPool (StrSize (LfnBuffer), LfnBuffer);\r
index ef1fd35e7eb0cdcd5328e5c0350e1e03308c46b7..b73135cdbc26354886fa233d9318698e797be94c 100644 (file)
@@ -1241,8 +1241,9 @@ FatSetCaseFlag (
 \r
 VOID\r
 FatGetFileNameViaCaseFlag (\r
-  IN  FAT_DIRENT        *DirEnt,\r
-  OUT CHAR16            *FileString\r
+  IN     FAT_DIRENT     *DirEnt,\r
+  IN OUT CHAR16         *FileString,\r
+  IN     UINTN          FileStringMax\r
   );\r
 \r
 UINT8\r
index 09690fb07649e606db329badaf0066dadbcbe11f..551cda53b9a4e5b968d4d5f364a61066b7471828 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution. The full text of the license may be found at\r
@@ -302,7 +302,6 @@ Returns:
   CHAR16  Buffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];\r
   UINT8   OutCaseFlag;\r
 \r
-  ASSERT (StrSize (Str) <= sizeof (Buffer));\r
   //\r
   // Assume the case of input string is mixed\r
   //\r
@@ -311,7 +310,7 @@ Returns:
   // Lower case a copy of the string, if it matches the\r
   // original then the string is lower case\r
   //\r
-  StrCpy (Buffer, Str);\r
+  StrCpyS (Buffer, sizeof (Buffer) / sizeof (Buffer[0]), Str);\r
   FatStrLwr (Buffer);\r
   if (StrCmp (Str, Buffer) == 0) {\r
     OutCaseFlag = InCaseFlag;\r
@@ -320,7 +319,7 @@ Returns:
   // Upper case a copy of the string, if it matches the\r
   // original then the string is upper case\r
   //\r
-  StrCpy (Buffer, Str);\r
+  StrCpyS (Buffer, sizeof (Buffer) / sizeof (Buffer[0]), Str);\r
   FatStrUpr (Buffer);\r
   if (StrCmp (Str, Buffer) == 0) {\r
     OutCaseFlag = 0;\r
@@ -392,8 +391,9 @@ Returns:
 \r
 VOID\r
 FatGetFileNameViaCaseFlag (\r
-  IN  FAT_DIRENT    *DirEnt,\r
-  OUT CHAR16        *FileString\r
+  IN     FAT_DIRENT   *DirEnt,\r
+  IN OUT CHAR16       *FileString,\r
+  IN     UINTN        FileStringMax\r
   )\r
 /*++\r
 \r
@@ -425,7 +425,7 @@ Returns:
   FatNameToStr (File8Dot3Name + FAT_MAIN_NAME_LEN, FAT_EXTEND_NAME_LEN, CaseFlag & FAT_CASE_EXT_LOWER, &TempExt[1]);\r
   if (TempExt[1] != 0) {\r
     TempExt[0] = L'.';\r
-    StrCat (FileString, TempExt);\r
+    StrCatS (FileString, FileStringMax, TempExt);\r
   }\r
 }\r
 \r
index dd67bab313d9c8ef9e5bd3dcb5bb8e0dfdcc0e2b..3d0ffe6fb8793c53cfefda4c3f333eda17795a3e 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution. The full text of the license may be found at\r
@@ -47,8 +47,12 @@ Returns:
 {\r
   UINT32  HashValue;\r
   CHAR16  UpCasedLongFileName[EFI_PATH_STRING_LENGTH];\r
-  StrnCpy (UpCasedLongFileName, LongNameString, EFI_PATH_STRING_LENGTH - 1);\r
-  UpCasedLongFileName[EFI_PATH_STRING_LENGTH - 1] = L'\0';\r
+  StrnCpyS (\r
+    UpCasedLongFileName,\r
+    sizeof (UpCasedLongFileName) / sizeof (UpCasedLongFileName[0]),\r
+    LongNameString,\r
+    sizeof (UpCasedLongFileName) / sizeof (UpCasedLongFileName[0]) - 1\r
+    );\r
   FatStrUpr (UpCasedLongFileName);\r
   gBS->CalculateCrc32 (UpCasedLongFileName, StrSize (UpCasedLongFileName), &HashValue);\r
   return (HashValue & HASH_TABLE_MASK);\r