From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DBAF42205B902 for ; Thu, 11 Jan 2018 07:15:54 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jan 2018 07:21:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,344,1511856000"; d="scan'208";a="23236605" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga001.jf.intel.com with ESMTP; 11 Jan 2018 07:21:07 -0800 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 11 Jan 2018 07:21:07 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 11 Jan 2018 07:21:06 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.152]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.218]) with mapi id 14.03.0319.002; Thu, 11 Jan 2018 23:21:05 +0800 From: "Gao, Liming" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] MdeModulePkg/DebugLib: Print partial when format string is too long Thread-Index: AQHTio1LdLsFdnzXzUC4VzdxBQ39RKNuykZw Date: Thu, 11 Jan 2018 15:21:04 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E1A379E@SHSMSX104.ccr.corp.intel.com> References: <20180111033552.46800-1-ruiyu.ni@intel.com> In-Reply-To: <20180111033552.46800-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdeModulePkg/DebugLib: Print partial when format string is too long X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jan 2018 15:15:55 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ray: Could you keep total size to point the real used size instead of full siz= e? 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 > Subject: [PATCH] MdeModulePkg/DebugLib: Print partial when format string = is too long >=20 > 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. >=20 > 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. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ruiyu Ni > Cc: Liming Gao > --- > .../PeiDxeDebugLibReportStatusCode/DebugLib.c | 21 +++++++--------= ------ > 1 file changed, 7 insertions(+), 14 deletions(-) >=20 > 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 allow= able > record length, then the debug message will be ignored directly. >=20 > - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
> + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
> 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 ( > } >=20 > // > - // 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 + size= of(Buffer) > // > - TotalSize =3D 4 + sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + Asc= iiStrSize (Format); > - > - // > - // If the TotalSize is larger than the maximum record size, then retur= n > - // > - if (TotalSize > sizeof (Buffer)) { > - return; > - } >=20 > // > // Fill in EFI_DEBUG_INFO > @@ -113,9 +103,12 @@ DebugPrint ( > FormatString =3D (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12); >=20 > // > - // 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_INF= O) + 12 * sizeof(UINT64)), Format); > + AsciiStrnCpyS ( > + FormatString, sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * si= zeof(UINT64)), > + Format, sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * si= zeof(UINT64)) - 1 > + ); >=20 > // > // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are f= or variable arguments > @@ -223,7 +216,7 @@ DebugPrint ( > NULL, > &gEfiStatusCodeDataTypeDebugGuid, > DebugInfo, > - TotalSize > + sizeof (Buffer) > ); > } >=20 > -- > 2.15.1.windows.2