]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/DefaultExceptionHandlerLib: replace AsciiStrCat() with AsciiStrCatS()
authorLaszlo Ersek <lersek@redhat.com>
Fri, 21 Oct 2016 19:31:09 +0000 (21:31 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Tue, 25 Oct 2016 08:46:42 +0000 (10:46 +0200)
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 <ard.biesheuvel@linaro.org>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Michael Zimmermann <sigmaepsilon92@gmail.com>
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 <lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c

index aece26355e2e72b37018a3b3d504af2f821116d1..0b9da031b47d85ed7cad5474d7c16a3eb8451832 100644 (file)
 #include <Protocol/DebugSupport.h>\r
 #include <Library/DefaultExceptionHandlerLib.h>\r
 \r
 #include <Protocol/DebugSupport.h>\r
 #include <Library/DefaultExceptionHandlerLib.h>\r
 \r
+//\r
+// The number of elements in a CHAR8 array, including the terminating NUL, that\r
+// is meant to hold the string rendering of the CPSR.\r
+//\r
+#define CPSR_STRING_SIZE 32\r
+\r
 typedef struct {\r
   UINT32  BIT;\r
   CHAR8   Char;\r
 typedef struct {\r
   UINT32  BIT;\r
   CHAR8   Char;\r
@@ -46,7 +52,8 @@ GetImageName (
   It is possible to add extra bits by adding them to CpsrChar array.\r
 \r
   @param  Cpsr         ARM CPSR register value\r
   It is possible to add extra bits by adding them to CpsrChar array.\r
 \r
   @param  Cpsr         ARM CPSR register value\r
-  @param  ReturnStr    32 byte string that contains string version of CPSR\r
+  @param  ReturnStr    CPSR_STRING_SIZE byte string that contains string\r
+                       version of CPSR\r
 \r
 **/\r
 VOID\r
 \r
 **/\r
 VOID\r
@@ -116,8 +123,10 @@ CpsrString (
     break;\r
   }\r
 \r
     break;\r
   }\r
 \r
-  AsciiStrCat (Str, ModeStr);\r
-  return;\r
+  //\r
+  // See the interface contract in the leading comment block.\r
+  //\r
+  AsciiStrCatS (Str, CPSR_STRING_SIZE - (Str - ReturnStr), ModeStr);\r
 }\r
 \r
 CHAR8 *\r
 }\r
 \r
 CHAR8 *\r
@@ -192,7 +201,8 @@ DefaultExceptionHandler (
     UINT32  ImageBase;\r
     UINT32  PeCoffSizeOfHeader;\r
     UINT32  Offset;\r
     UINT32  ImageBase;\r
     UINT32  PeCoffSizeOfHeader;\r
     UINT32  Offset;\r
-    CHAR8   CpsrStr[32];  // char per bit. Lower 5-bits are mode that is a 3 char string\r
+    CHAR8   CpsrStr[CPSR_STRING_SIZE];  // char per bit. Lower 5-bits are mode\r
+                                        // that is a 3 char string\r
     CHAR8   Buffer[80];\r
     UINT8   *DisAsm;\r
     UINT32  ItBlock;\r
     CHAR8   Buffer[80];\r
     UINT8   *DisAsm;\r
     UINT32  ItBlock;\r