From: <yd...@us...> - 2014-06-09 10:33:29
|
Revision: 2666 http://sourceforge.net/p/edk2-buildtools/code/2666 Author: ydong10 Date: 2014-06-09 10:33:24 +0000 (Mon, 09 Jun 2014) Log Message: ----------- Add report error message logic for string to integer functions in VfrCompiler (STOU8, STOU16, STOU32, STOU64). Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Aaron Pop <aa...@am...> Reviewed-by: Eric Dong <eri...@in...> Modified Paths: -------------- trunk/BaseTools/Source/C/VfrCompile/VfrSyntax.g Modified: trunk/BaseTools/Source/C/VfrCompile/VfrSyntax.g =================================================================== --- trunk/BaseTools/Source/C/VfrCompile/VfrSyntax.g 2014-06-09 10:27:59 UTC (rev 2665) +++ trunk/BaseTools/Source/C/VfrCompile/VfrSyntax.g 2014-06-09 10:33:24 UTC (rev 2666) @@ -4344,11 +4344,13 @@ UINT8 Value; CHAR8 c; + UINT8 PreviousValue; + CHAR8 *OrigString = Str; + CHAR8 ErrorMsg[100]; + Str = TrimHex (Str, &IsHex); for (Value = 0; (c = *Str) != '\0'; Str++) { - // - // BUG: does not handle overflow here - // + PreviousValue = Value; (IsHex == TRUE) ? (Value <<= 4) : (Value *= 10); if ((IsHex == TRUE) && (c >= 'a') && (c <= 'f')) { @@ -4360,6 +4362,10 @@ if (c >= '0' && c <= '9') { Value += (c - '0'); } + if((IsHex && ((Value/16) != PreviousValue)) || (!IsHex && ((Value/10) != PreviousValue))) { + sprintf(ErrorMsg, "Overflow: Value %s is too large to store in a UINT8", OrigString); + _PCATCH (VFR_RETURN_INVALID_PARAMETER, 0, ErrorMsg); + } } return Value; @@ -4374,11 +4380,13 @@ UINT16 Value; CHAR8 c; + UINT16 PreviousValue; + CHAR8 *OrigString = Str; + CHAR8 ErrorMsg[100]; + Str = TrimHex (Str, &IsHex); for (Value = 0; (c = *Str) != '\0'; Str++) { - // - // BUG: does not handle overflow here - // + PreviousValue = Value; (IsHex == TRUE) ? (Value <<= 4) : (Value *= 10); if ((IsHex == TRUE) && (c >= 'a') && (c <= 'f')) { @@ -4390,6 +4398,10 @@ if (c >= '0' && c <= '9') { Value += (c - '0'); } + if((IsHex && ((Value/16) != PreviousValue)) || (!IsHex && ((Value/10) != PreviousValue))) { + sprintf(ErrorMsg, "Overflow: Value %s is too large to store in a UINT16", OrigString); + _PCATCH (VFR_RETURN_INVALID_PARAMETER, 0, ErrorMsg); + } } return Value; @@ -4404,11 +4416,13 @@ UINT32 Value; CHAR8 c; + UINT32 PreviousValue; + CHAR8 *OrigString = Str; + CHAR8 ErrorMsg[100]; + Str = TrimHex (Str, &IsHex); for (Value = 0; (c = *Str) != '\0'; Str++) { - // - // BUG: does not handle overflow here - // + PreviousValue = Value; (IsHex == TRUE) ? (Value <<= 4) : (Value *= 10); if ((IsHex == TRUE) && (c >= 'a') && (c <= 'f')) { @@ -4420,6 +4434,10 @@ if (c >= '0' && c <= '9') { Value += (c - '0'); } + if((IsHex && ((Value/16) != PreviousValue)) || (!IsHex && ((Value/10) != PreviousValue ))) { + sprintf(ErrorMsg, "Overflow: Value %s is too large to store in a UINT32", OrigString); + _PCATCH (VFR_RETURN_INVALID_PARAMETER, 0, ErrorMsg); + } } return Value; @@ -4433,12 +4451,13 @@ BOOLEAN IsHex; UINT64 Value; CHAR8 c; + UINT64 PreviousValue; + CHAR8 *OrigString = Str; + CHAR8 ErrorMsg[100]; Str = TrimHex (Str, &IsHex); for (Value = 0; (c = *Str) != '\0'; Str++) { - // - // BUG: does not handle overflow here - // + PreviousValue = Value; (IsHex == TRUE) ? (Value <<= 4) : (Value *= 10); if ((IsHex == TRUE) && (c >= 'a') && (c <= 'f')) { @@ -4450,6 +4469,10 @@ if (c >= '0' && c <= '9') { Value += (c - '0'); } + if((IsHex && ((Value/16) != PreviousValue)) || ((!IsHex && (Value/10) != PreviousValue))) { + sprintf(ErrorMsg, "Overflow: Value %s is too large to store in a UINT64", OrigString); + _PCATCH (VFR_RETURN_INVALID_PARAMETER, 0, ErrorMsg); + } } return Value; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |