public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/DebugLib: Print partial when format string is too long
@ 2018-01-11  3:35 Ruiyu Ni
  2018-01-11 15:21 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Ruiyu Ni @ 2018-01-11  3:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao

Today's implementation prints nothing when the format string cannot
fit in the report status extended data buffer.
It confuses user.
The patch changes to print partial message by truncating the format
string when it's too long.

The missing enhancement is the extended data buffer only reserves 96
bytes for the var-args. When the format string is not very long but
contains 13 %lx or %p, the var-args buffer is too small. Today's
implementation prints nothing for this case.
This patch doesn't change such behavior.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 .../PeiDxeDebugLibReportStatusCode/DebugLib.c       | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
index 163d530ae5..785e231cf2 100644
--- a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
+++ b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
@@ -4,7 +4,7 @@
   Note that if the debug message length is larger than the maximum allowable
   record length, then the debug message will be ignored directly.
 
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -55,7 +55,6 @@ DebugPrint (
 {
   UINT64          Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];
   EFI_DEBUG_INFO  *DebugInfo;
-  UINTN           TotalSize;
   VA_LIST         VaListMarker;
   BASE_LIST       BaseListMarker;
   CHAR8           *FormatString;
@@ -74,7 +73,6 @@ DebugPrint (
   }
 
   //
-  // Compute the total size of the record.
   // Note that the passing-in format string and variable parameters will be constructed to 
   // the following layout:
   //
@@ -90,14 +88,6 @@ DebugPrint (
   //                 |       Format String    |
   //                 |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)
   //
-  TotalSize = 4 + sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrSize (Format);
-
-  //
-  // If the TotalSize is larger than the maximum record size, then return
-  //
-  if (TotalSize > sizeof (Buffer)) {
-    return;
-  }
 
   //
   // Fill in EFI_DEBUG_INFO
@@ -113,9 +103,12 @@ DebugPrint (
   FormatString          = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);
 
   //
-  // Copy the Format string into the record
+  // Copy the Format string into the record. It will be truncated if it's too long.
   //
-  AsciiStrCpyS (FormatString, sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)), Format);
+  AsciiStrnCpyS (
+    FormatString, sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)),
+    Format,       sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)) - 1
+    );
 
   //
   // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments
@@ -223,7 +216,7 @@ DebugPrint (
     NULL,
     &gEfiStatusCodeDataTypeDebugGuid,
     DebugInfo,
-    TotalSize
+    sizeof (Buffer)
     );
 }
 
-- 
2.15.1.windows.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] MdeModulePkg/DebugLib: Print partial when format string is too long
  2018-01-11  3:35 [PATCH] MdeModulePkg/DebugLib: Print partial when format string is too long Ruiyu Ni
@ 2018-01-11 15:21 ` Gao, Liming
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Liming @ 2018-01-11 15:21 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org

Ray:
  Could you keep total size to point the real used size instead of full size? It can reduce the copy action in ReportStatusCodeLib.

> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Thursday, January 11, 2018 11:36 AM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming <liming.gao@intel.com>
> Subject: [PATCH] MdeModulePkg/DebugLib: Print partial when format string is too long
> 
> Today's implementation prints nothing when the format string cannot
> fit in the report status extended data buffer.
> It confuses user.
> The patch changes to print partial message by truncating the format
> string when it's too long.
> 
> The missing enhancement is the extended data buffer only reserves 96
> bytes for the var-args. When the format string is not very long but
> contains 13 %lx or %p, the var-args buffer is too small. Today's
> implementation prints nothing for this case.
> This patch doesn't change such behavior.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> ---
>  .../PeiDxeDebugLibReportStatusCode/DebugLib.c       | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> index 163d530ae5..785e231cf2 100644
> --- a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> +++ b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> @@ -4,7 +4,7 @@
>    Note that if the debug message length is larger than the maximum allowable
>    record length, then the debug message will be ignored directly.
> 
> -  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD License
>    which accompanies this distribution.  The full text of the license may be found at
> @@ -55,7 +55,6 @@ DebugPrint (
>  {
>    UINT64          Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];
>    EFI_DEBUG_INFO  *DebugInfo;
> -  UINTN           TotalSize;
>    VA_LIST         VaListMarker;
>    BASE_LIST       BaseListMarker;
>    CHAR8           *FormatString;
> @@ -74,7 +73,6 @@ DebugPrint (
>    }
> 
>    //
> -  // Compute the total size of the record.
>    // Note that the passing-in format string and variable parameters will be constructed to
>    // the following layout:
>    //
> @@ -90,14 +88,6 @@ DebugPrint (
>    //                 |       Format String    |
>    //                 |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)
>    //
> -  TotalSize = 4 + sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrSize (Format);
> -
> -  //
> -  // If the TotalSize is larger than the maximum record size, then return
> -  //
> -  if (TotalSize > sizeof (Buffer)) {
> -    return;
> -  }
> 
>    //
>    // Fill in EFI_DEBUG_INFO
> @@ -113,9 +103,12 @@ DebugPrint (
>    FormatString          = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);
> 
>    //
> -  // Copy the Format string into the record
> +  // Copy the Format string into the record. It will be truncated if it's too long.
>    //
> -  AsciiStrCpyS (FormatString, sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)), Format);
> +  AsciiStrnCpyS (
> +    FormatString, sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)),
> +    Format,       sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)) - 1
> +    );
> 
>    //
>    // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments
> @@ -223,7 +216,7 @@ DebugPrint (
>      NULL,
>      &gEfiStatusCodeDataTypeDebugGuid,
>      DebugInfo,
> -    TotalSize
> +    sizeof (Buffer)
>      );
>  }
> 
> --
> 2.15.1.windows.2



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-11 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-11  3:35 [PATCH] MdeModulePkg/DebugLib: Print partial when format string is too long Ruiyu Ni
2018-01-11 15:21 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox