]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFv: Add checks for user/file inputs
authorHao Wu <hao.a.wu@intel.com>
Tue, 11 Oct 2016 03:13:41 +0000 (11:13 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 8 Nov 2016 08:37:12 +0000 (16:37 +0800)
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/GenFv/GenFv.c
BaseTools/Source/C/GenFv/GenFvInternalLib.c

index 01ae37acd738fcaa40b04e7c3acf16c3d3ca6eaf..4de24b9f7ec1b610b2158b468d99b8886607f8af 100644 (file)
@@ -4,7 +4,7 @@
   can be found in the Tiano Firmware Volume Generation Utility \r
   Specification, review draft.\r
 \r
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, 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
@@ -337,7 +337,12 @@ Returns:
         Error (NULL, 0, 1003, "Invalid option value", "Input Ffsfile can't be null");\r
         return STATUS_ERROR;\r
       }\r
-      strcpy (mFvDataInfo.FvFiles[Index], argv[1]);\r
+      if (strlen (argv[1]) > MAX_LONG_FILE_PATH - 1) {\r
+        Error (NULL, 0, 1003, "Invalid option value", "Input Ffsfile name %s is too long!", argv[1]);\r
+        return STATUS_ERROR;\r
+      }\r
+      strncpy (mFvDataInfo.FvFiles[Index], argv[1], MAX_LONG_FILE_PATH - 1);\r
+      mFvDataInfo.FvFiles[Index][MAX_LONG_FILE_PATH - 1] = 0;\r
       DebugMsg (NULL, 0, 9, "FV component file", "the %uth name is %s", (unsigned) Index + 1, argv[1]);\r
       argc -= 2;\r
       argv += 2;\r
index 7e8b0ed2d8cf01943cb246218a45f787f4bf8d1b..d16b33eee330fcc64078455d5e1bf54589a75efe 100644 (file)
@@ -374,7 +374,7 @@ Returns:
     }\r
   }\r
 \r
-  for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_FV; Index++) {\r
+  for (Index = 0; Number + Index < MAX_NUMBER_OF_FILES_IN_FV; Index++) {\r
     //\r
     // Read the FFS file list\r
     //\r
@@ -2418,17 +2418,19 @@ Returns:
   UINT8                           *FvImage;\r
   UINTN                           FvImageSize;\r
   FILE                            *FvFile;\r
-  CHAR8                           FvMapName [MAX_LONG_FILE_PATH];\r
+  CHAR8                           *FvMapName;\r
   FILE                            *FvMapFile;\r
   EFI_FIRMWARE_VOLUME_EXT_HEADER  *FvExtHeader;\r
   FILE                            *FvExtHeaderFile;\r
   UINTN                           FileSize;\r
-  CHAR8                           FvReportName[MAX_LONG_FILE_PATH];\r
+  CHAR8                           *FvReportName;\r
   FILE                            *FvReportFile;\r
 \r
   FvBufferHeader = NULL;\r
   FvFile         = NULL;\r
+  FvMapName      = NULL;\r
   FvMapFile      = NULL;\r
+  FvReportName   = NULL;\r
   FvReportFile   = NULL;\r
 \r
   if (InfFileImage != NULL) {\r
@@ -2566,8 +2568,34 @@ Returns:
   // FvMap file to log the function address of all modules in one Fvimage\r
   //\r
   if (MapFileName != NULL) {\r
+    if (strlen (MapFileName) > MAX_LONG_FILE_PATH - 1) {\r
+      Error (NULL, 0, 1003, "Invalid option value", "MapFileName %s is too long!", MapFileName);\r
+      Status = EFI_ABORTED;\r
+      goto Finish;\r
+    }\r
+\r
+    FvMapName = malloc (strlen (MapFileName) + 1);\r
+    if (FvMapName == NULL) {\r
+      Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Finish;\r
+    }\r
+\r
     strcpy (FvMapName, MapFileName);\r
   } else {\r
+    if (strlen (FvFileName) + strlen (".map") > MAX_LONG_FILE_PATH - 1) {\r
+      Error (NULL, 0, 1003, "Invalid option value", "FvFileName %s is too long!", FvFileName);\r
+      Status = EFI_ABORTED;\r
+      goto Finish;\r
+    }\r
+\r
+    FvMapName = malloc (strlen (FvFileName) + strlen (".map") + 1);\r
+    if (FvMapName == NULL) {\r
+      Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Finish;\r
+    }\r
+\r
     strcpy (FvMapName, FvFileName);\r
     strcat (FvMapName, ".map");\r
   }\r
@@ -2576,6 +2604,19 @@ Returns:
   //\r
   // FvReport file to log the FV information in one Fvimage\r
   //\r
+  if (strlen (FvFileName) + strlen (".txt") > MAX_LONG_FILE_PATH - 1) {\r
+    Error (NULL, 0, 1003, "Invalid option value", "FvFileName %s is too long!", FvFileName);\r
+    Status = EFI_ABORTED;\r
+    goto Finish;\r
+  }\r
+\r
+  FvReportName = malloc (strlen (FvFileName) + strlen (".txt") + 1);\r
+  if (FvReportName == NULL) {\r
+    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Finish;\r
+  }\r
+\r
   strcpy (FvReportName, FvFileName);\r
   strcat (FvReportName, ".txt");\r
 \r
@@ -2852,6 +2893,14 @@ Finish:
   if (FvExtHeader != NULL) {\r
     free (FvExtHeader);\r
   }\r
+\r
+  if (FvMapName != NULL) {\r
+    free (FvMapName);\r
+  }\r
+\r
+  if (FvReportName != NULL) {\r
+    free (FvReportName);\r
+  }\r
   \r
   if (FvFile != NULL) {\r
     fflush (FvFile);\r