From: "Krzysztof Koch" <krzysztof.koch@arm.com>
To: <devel@edk2.groups.io>
Cc: <jaben.carsey@intel.com>, <ray.ni@intel.com>,
<zhichao.gao@intel.com>, <Sami.Mujawar@arm.com>,
<Matteo.Carlini@arm.com>, <nd@arm.com>
Subject: [PATCH v2 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
Date: Mon, 22 Jul 2019 08:50:21 +0100 [thread overview]
Message-ID: <20190722075026.20244-2-krzysztof.koch@arm.com> (raw)
In-Reply-To: <20190722075026.20244-1-krzysztof.koch@arm.com>
Modify the signature of the DumpGasStruct() function to include the
buffer length parameter and to return the number of bytes parsed by
the function.
This way it becomes possible to prevent buffer overruns when dumping
Generic Address Structure's (GAS) fields in the acpiview table
parsers.
Update all existing DumpGasStruct() calls in acpiview to add the
length argument.
Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---
Notes:
v2:
- Pass GAS_LENGTH to DumpGasStruct() in DBG2 parser [Zhichao]
v1:
- Modify DumpGasStruct() signature [Krzysztof]
ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c | 26 +++++++++++---------
ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h | 8 ++++--
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 2 +-
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3db89332197c0dc0e 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = {
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Indent Number of spaces to indent the output.
+ @param [in] Length Length of the GAS structure buffer.
+
+ @retval Number of bytes parsed.
**/
-VOID
+UINT32
EFIAPI
DumpGasStruct (
IN UINT8* Ptr,
- IN UINT32 Indent
+ IN UINT32 Indent,
+ IN UINT32 Length
)
{
Print (L"\n");
- ParseAcpi (
- TRUE,
- Indent,
- NULL,
- Ptr,
- GAS_LENGTH,
- PARSER_PARAMS (GasParser)
- );
+ return ParseAcpi (
+ TRUE,
+ Indent,
+ NULL,
+ Ptr,
+ Length,
+ PARSER_PARAMS (GasParser)
+ );
}
/**
@@ -621,7 +625,7 @@ DumpGas (
IN UINT8* Ptr
)
{
- DumpGasStruct (Ptr, 2);
+ DumpGasStruct (Ptr, 2, GAS_LENGTH);
}
/**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 7657892d9fd2e2e14c6578611ff0cf1b6f6cd750..20ca358bddfa5953bfb1d1bebaebbf3079eaba01 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -405,12 +405,16 @@ ParseAcpi (
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Indent Number of spaces to indent the output.
+ @param [in] Length Length of the GAS structure buffer.
+
+ @retval Number of bytes parsed.
**/
-VOID
+UINT32
EFIAPI
DumpGasStruct (
IN UINT8* Ptr,
- IN UINT32 Indent
+ IN UINT32 Indent,
+ IN UINT32 Length
);
/**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 1efcbd40f86efdabed2152540a415db8a950fb71..c6929695a1032c57761ef85002d6c51b7800ce23 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -134,7 +134,7 @@ DumpDbgDeviceInfo (
AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));
while (Index < (*GasCount)) {
PrintFieldName (4, L"BaseAddressRegister");
- DumpGasStruct (DataPtr, 4);
+ DumpGasStruct (DataPtr, 4, GAS_LENGTH);
PrintFieldName (4, L"Address Size");
Print (L"0x%x\n", AddrSize[Index]);
DataPtr += GAS_LENGTH;
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
next prev parent reply other threads:[~2019-07-22 7:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-22 7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
2019-07-22 7:50 ` Krzysztof Koch [this message]
2019-07-22 7:50 ` [PATCH v2 2/6] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call Krzysztof Koch
2019-07-22 7:50 ` [PATCH v2 3/6] ShellPkg: acpiview: RSDP: Make code consistent with other parsers Krzysztof Koch
2019-07-22 7:50 ` [PATCH v2 4/6] ShellPkg: acpiview: SRAT: Minor code style enhancements Krzysztof Koch
2019-07-22 7:50 ` [PATCH v2 5/6] ShellPkg: acpiview: MADT: Split structure length validation Krzysztof Koch
2019-07-22 7:50 ` [PATCH v2 6/6] ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation Krzysztof Koch
2019-07-22 9:11 ` [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Gao, Zhichao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190722075026.20244-2-krzysztof.koch@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox