]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/VfrCompile: report error for Integer overflow
authorDandan Bi <dandan.bi@intel.com>
Fri, 28 Dec 2018 08:18:06 +0000 (16:18 +0800)
committerLiming Gao <liming.gao@intel.com>
Tue, 8 Jan 2019 01:59:30 +0000 (09:59 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1415

When an integer constant specified in the .vfr file is
too large for the varstore field it is being used with,
the VFR compiler reports an overflow warning like this:
Test.vfr(693): WARNING: Overflow: Value 1024 is too large to
         store in a UINT8
    : String to UINT* Overflow
Since Warning does not break the build process,
and it is easy to miss it.
This patch is to update the code to report error and break
the build if meet this kind of issue.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/VfrCompile/VfrError.cpp
BaseTools/Source/C/VfrCompile/VfrError.h
BaseTools/Source/C/VfrCompile/VfrSyntax.g

index bbf738c21766bbfa397605c64aee9130fa5cddcf..c105d73bea740a442f259e8988c9d0bfd999881f 100644 (file)
@@ -47,12 +47,12 @@ static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE [] = {
   { VFR_RETURN_CONSTANT_ONLY, ": only constant is allowed in the expression"},\r
   { VFR_RETURN_VARSTORE_NAME_REDEFINED_ERROR, ": Varstore name is defined by more than one varstores, it can't be referred as varstore, only varstore strucure name could be used."},\r
   { VFR_RETURN_BIT_WIDTH_ERROR, ": bit width must be <= sizeof (type) * 8 and the max width can not > 32" },\r
+  { VFR_RETURN_STRING_TO_UINT_OVERFLOW, ": String to UINT* Overflow"},\r
   { VFR_RETURN_CODEUNDEFINED, ": undefined Error Code" }\r
 };\r
 \r
 static SVFR_WARNING_HANDLE VFR_WARNING_HANDLE_TABLE [] = {\r
   { VFR_WARNING_DEFAULT_VALUE_REDEFINED, ": default value re-defined with different value"},\r
-  { VFR_WARNING_STRING_TO_UINT_OVERFLOW, ": String to UINT* Overflow"},\r
   { VFR_WARNING_ACTION_WITH_TEXT_TWO, ": Action opcode should not have TextTwo part"},\r
   { VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE, ": Not recommend to use obsoleted framework opcode"},\r
   { VFR_WARNING_CODEUNDEFINED, ": undefined Warning Code" }\r
index e83ae900fab75439f1103aeb4a714740b45b21cb..e795f1631d39e9ef66691a5133a0a3877e29a1e6 100644 (file)
@@ -45,12 +45,12 @@ typedef enum {
   VFR_RETURN_CONSTANT_ONLY,\r
   VFR_RETURN_VARSTORE_NAME_REDEFINED_ERROR,\r
   VFR_RETURN_BIT_WIDTH_ERROR,\r
+  VFR_RETURN_STRING_TO_UINT_OVERFLOW,\r
   VFR_RETURN_CODEUNDEFINED\r
 } EFI_VFR_RETURN_CODE;\r
 \r
 typedef enum {\r
   VFR_WARNING_DEFAULT_VALUE_REDEFINED = 0,\r
-  VFR_WARNING_STRING_TO_UINT_OVERFLOW,\r
   VFR_WARNING_ACTION_WITH_TEXT_TWO,\r
   VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE,\r
   VFR_WARNING_CODEUNDEFINED\r
index 84dd2c3ed3fde43087f78f5e07fe3ac7f506f3d0..c72a62ae91241593e73fceaf14950f354fab4829 100644 (file)
@@ -1,7 +1,7 @@
 /*++ @file\r
 Vfr Syntax\r
 \r
-Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2018, 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
@@ -5322,7 +5322,7 @@ EfiVfrParser::_STOU8 (
     }\r
     if((IsHex && ((Value/16) != PreviousValue)) || (!IsHex && ((Value/10) != PreviousValue))) {\r
       sprintf(ErrorMsg, "Overflow: Value %s is too large to store in a UINT8", OrigString);\r
-      gCVfrErrorHandle.HandleWarning (VFR_WARNING_STRING_TO_UINT_OVERFLOW, LineNum, ErrorMsg);\r
+      mParserStatus = mParserStatus + gCVfrErrorHandle.HandleError (VFR_RETURN_STRING_TO_UINT_OVERFLOW, LineNum, ErrorMsg);\r
     }\r
   }\r
 \r
@@ -5359,7 +5359,7 @@ EfiVfrParser::_STOU16 (
     }\r
     if((IsHex && ((Value/16) != PreviousValue)) || (!IsHex && ((Value/10) != PreviousValue))) {\r
       sprintf(ErrorMsg, "Overflow: Value %s is too large to store in a UINT16", OrigString);\r
-      gCVfrErrorHandle.HandleWarning (VFR_WARNING_STRING_TO_UINT_OVERFLOW, LineNum, ErrorMsg);\r
+      mParserStatus = mParserStatus + gCVfrErrorHandle.HandleError (VFR_RETURN_STRING_TO_UINT_OVERFLOW, LineNum, ErrorMsg);\r
     }\r
   }\r
 \r
@@ -5396,7 +5396,7 @@ EfiVfrParser::_STOU32 (
     }\r
     if((IsHex && ((Value/16) != PreviousValue)) || (!IsHex && ((Value/10) != PreviousValue ))) {\r
       sprintf(ErrorMsg, "Overflow: Value %s is too large to store in a UINT32", OrigString);\r
-      gCVfrErrorHandle.HandleWarning (VFR_WARNING_STRING_TO_UINT_OVERFLOW, LineNum, ErrorMsg);\r
+      mParserStatus = mParserStatus + gCVfrErrorHandle.HandleError (VFR_RETURN_STRING_TO_UINT_OVERFLOW, LineNum, ErrorMsg);\r
     }\r
   }\r
 \r
@@ -5432,7 +5432,7 @@ EfiVfrParser::_STOU64 (
     }\r
     if((IsHex && ((Value/16) != PreviousValue)) || ((!IsHex && (Value/10) != PreviousValue))) {\r
       sprintf(ErrorMsg, "Overflow: Value %s is too large to store in a UINT64", OrigString);\r
-      gCVfrErrorHandle.HandleWarning (VFR_WARNING_STRING_TO_UINT_OVERFLOW, LineNum, ErrorMsg);\r
+      mParserStatus = mParserStatus + gCVfrErrorHandle.HandleError (VFR_RETURN_STRING_TO_UINT_OVERFLOW, LineNum, ErrorMsg);\r
     }\r
   }\r
 \r