]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/C/Common: Add checks for array access
authorHao Wu <hao.a.wu@intel.com>
Thu, 30 Nov 2017 06:29:25 +0000 (14:29 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 25 Dec 2017 01:53:29 +0000 (09:53 +0800)
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/Common/Decompress.c
BaseTools/Source/C/Common/SimpleFileParsing.c

index b2049bd01c5f452149b8fe19f9e33df7309f83a6..8f1afb4e406e0d7bf4250451218ff9b683f6807f 100644 (file)
@@ -2,7 +2,7 @@
 Decompressor. Algorithm Ported from OPSD code (Decomp.asm) for Efi and Tiano \r
 compress algorithm.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, 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
@@ -394,7 +394,7 @@ Returns:
 \r
   Index = 0;\r
 \r
-  while (Index < Number) {\r
+  while (Index < Number && Index < NPT) {\r
 \r
     CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));\r
 \r
@@ -413,14 +413,14 @@ Returns:
     if (Index == Special) {\r
       CharC = (UINT16) GetBits (Sd, 2);\r
       CharC--;\r
-      while ((INT16) (CharC) >= 0) {\r
+      while ((INT16) (CharC) >= 0 && Index < NPT) {\r
         Sd->mPTLen[Index++] = 0;\r
         CharC--;\r
       }\r
     }\r
   }\r
 \r
-  while (Index < nn) {\r
+  while (Index < nn && Index < NPT) {\r
     Sd->mPTLen[Index++] = 0;\r
   }\r
 \r
index 868c6b794b99fa240a31e884131671b0e1b16f33..209a0954b3f22031b98daab3e51e309c7eb59b6f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Generic but simple file parsing routines.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, 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
@@ -1232,12 +1232,10 @@ GetHexChars (
 {\r
   UINT32  Len;\r
   Len = 0;\r
-  while (!EndOfFile (&mGlobals.SourceFile) && (BufferLen > 0)) {\r
+  while (!EndOfFile (&mGlobals.SourceFile) && (Len < BufferLen)) {\r
     if (isxdigit ((int)mGlobals.SourceFile.FileBufferPtr[0])) {\r
-      *Buffer = mGlobals.SourceFile.FileBufferPtr[0];\r
-      Buffer++;\r
+      Buffer[Len] = mGlobals.SourceFile.FileBufferPtr[0];\r
       Len++;\r
-      BufferLen--;\r
       mGlobals.SourceFile.FileBufferPtr++;\r
     } else {\r
       break;\r
@@ -1246,8 +1244,8 @@ GetHexChars (
   //\r
   // Null terminate if we can\r
   //\r
-  if ((Len > 0) && (BufferLen > 0)) {\r
-    *Buffer = 0;\r
+  if ((Len > 0) && (Len < BufferLen)) {\r
+    Buffer[Len] = 0;\r
   }\r
 \r
   return Len;\r