From: Laszlo Ersek Date: Fri, 21 Oct 2016 19:31:09 +0000 (+0200) Subject: ArmPkg/DefaultExceptionHandlerLib: replace AsciiStrCat() with AsciiStrCatS() X-Git-Tag: edk2-stable201903~5520 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=a1848bc088c62ae5a19e20e95c22d7b4fb75d2cb ArmPkg/DefaultExceptionHandlerLib: replace AsciiStrCat() with AsciiStrCatS() AsciiStrCat() is deprecated / disabled under the DISABLE_NEW_DEPRECATED_INTERFACES feature test macro. The caller of CpsrString() is required to pass in "ReturnStr" with 32 CHAR8 elements. (DefaultExceptionHandler() complies with this.) "Str" is used to build "ReturnStr" gradually. Just before calling AsciiStrCat(), "Str" points to the then-terminating NUL character in "ReturnStr". The difference (Str - ReturnStr) gives the number of non-NUL characters we've written thus far, hence (32 - (Str - ReturnStr)) yields the number of remaining bytes in ReturnStr, including the ultimately terminating NUL character. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Michael Zimmermann Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=164 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=165 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel Reviewed-by: Jordan Justen --- diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c b/ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c index aece26355e..0b9da031b4 100644 --- a/ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c @@ -27,6 +27,12 @@ #include #include +// +// The number of elements in a CHAR8 array, including the terminating NUL, that +// is meant to hold the string rendering of the CPSR. +// +#define CPSR_STRING_SIZE 32 + typedef struct { UINT32 BIT; CHAR8 Char; @@ -46,7 +52,8 @@ GetImageName ( It is possible to add extra bits by adding them to CpsrChar array. @param Cpsr ARM CPSR register value - @param ReturnStr 32 byte string that contains string version of CPSR + @param ReturnStr CPSR_STRING_SIZE byte string that contains string + version of CPSR **/ VOID @@ -116,8 +123,10 @@ CpsrString ( break; } - AsciiStrCat (Str, ModeStr); - return; + // + // See the interface contract in the leading comment block. + // + AsciiStrCatS (Str, CPSR_STRING_SIZE - (Str - ReturnStr), ModeStr); } CHAR8 * @@ -192,7 +201,8 @@ DefaultExceptionHandler ( UINT32 ImageBase; UINT32 PeCoffSizeOfHeader; UINT32 Offset; - CHAR8 CpsrStr[32]; // char per bit. Lower 5-bits are mode that is a 3 char string + CHAR8 CpsrStr[CPSR_STRING_SIZE]; // char per bit. Lower 5-bits are mode + // that is a 3 char string CHAR8 Buffer[80]; UINT8 *DisAsm; UINT32 ItBlock;