Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve robustness of XmlTreeLib #458

Open
wants to merge 2 commits into
base: release/202311
Choose a base branch
from

Conversation

yangrongwei
Copy link
Contributor

Description

Improve robustness of XmlTreeLib for handling tailing invalid (?) characters.

Current XmlTreeLib will run into endless loop if there are some non-whitespace chars after root node. Take malloc() on Windows as an example, the memory will be initialized to 0xcd on debug build. If we put data on this buffer without a proper ending char (null), the CreateXmlTree() call will never return on this buffer.

This is strange. A better parser lib should (a) report this as an error or (2) stop parsing at the place.

This PR will stop parsing after first Root node was parsed, discarding any characters after it. As a side effect, if we have more than one root, only the first root will be reported. This is reasonable, since XML allows only one root node.

  • Impacts functionality?
    • Functionality - Does the change ultimately impact how firmware functions?
    • Examples: Add a new library, publish a new PPI, update an algorithm, ...
  • Impacts security?
    • Security - Does the change have a direct security impact on an application,
      flow, or firmware?
    • Examples: Crypto algorithm change, buffer overflow fix, parameter
      validation improvement, ...
  • Breaking change?
    • Breaking change - Will anyone consuming this change experience a break
      in build or boot behavior?
    • Examples: Add a new library class, move a module to a different repo, call
      a function in a new library class in a pre-existing module, ...
  • [ X] Includes tests?
    • Tests - Does the change include any explicit test code?
    • Examples: Unit tests, integration tests, robot tests, ...
  • Includes documentation?
    • Documentation - Does the change contain explicit documentation additions
      outside direct code modifications (and comments)?
    • Examples: Update readme file, add feature readme file, link to documentation
      on an a separate Web page, ...

How This Was Tested

Added test cases and passed unit test on host test.

Integration Instructions

None.

@github-actions github-actions bot added impact:non-functional Does not have a functional impact impact:testing Affects testing labels Apr 9, 2024
@yangrongwei
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Raymond Yang"

@@ -877,14 +877,15 @@ BuildNodeList (
//
Status = RtlXmlNextToken (&State, &Next, FALSE);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "Failed to get the next token, Status = 0x%x\n", Status));
DEBUG ((EFI_D_ERROR, "Failed to get the next token, Status = %r\n", Status)); // MS_CHANGE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MS_CHANGE tags aren't needed for the mu_plus repo (since this entire repo represents mu value adds). For future reference, MU_CHANGE is preferred for repos that do have upstream components that we track changes against.

// Topmost node, ignore tailing characters
//
// DONE-CCC:
// See also, TODO-AAA and TODO-BBB in `xml_fasterxml.c`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave full comments, please don't use annotations like DONE-CCC or TODO-AAA.

// if (pRawToken->TokenName == NTXML_RAWTOKEN_ERROR) {
// pToken->fError = TRUE;
// success = EFI_ABORTED;
// return success;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of commenting out the code, we can remove it. If it is helpful, do leave a full comment explaining why we don't check if the TokenName == NTXML_RAWTOKEN_ERROR.

@@ -2946,6 +2962,14 @@ RtlXmlNextToken (

cbTotalTokenLength = pRawToken->Run.cbData;

// MS_CHANGE
//
// TODO-AAA:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO fixable now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact:non-functional Does not have a functional impact impact:testing Affects testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants