diff --git a/XmlSupportPkg/Library/XmlTreeLib/XmlTreeLib.c b/XmlSupportPkg/Library/XmlTreeLib/XmlTreeLib.c index 2c6d7b3eea..2032832cf0 100644 --- a/XmlSupportPkg/Library/XmlTreeLib/XmlTreeLib.c +++ b/XmlSupportPkg/Library/XmlTreeLib/XmlTreeLib.c @@ -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 goto Exit; } else if (Next.fError) { // // Errors in parse, such as bad characters, come out here in the // fError member // - DEBUG ((EFI_D_ERROR, "Error during tokenization, Status = 0x%x\n", Next.fError)); + DEBUG ((EFI_D_ERROR, "Error during tokenization, Next.fError = %d\n", Next.fError)); // MS_CHANGE + Status = EFI_ABORTED; // MS_CHANGE goto Exit; } @@ -1071,7 +1072,7 @@ BuildNodeList ( // Status = AddAttributeToNode (CurrentNode, AttributeName, AttributeValue); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "ERROR: AddAttributeToNode() failed, Status = 0x%x\n", Status)); + DEBUG ((EFI_D_ERROR, "ERROR: AddAttributeToNode() failed, Status = %r\n", Status)); // MS_CHANGE goto Exit; } } else if (Next.State == XTSS_ENDELEMENT_NAME) { @@ -1105,6 +1106,20 @@ BuildNodeList ( // if (CurrentNode) { CurrentNode = CurrentNode->ParentNode; + // MS_CHANGE [begin] + // + // Topmost node, ignore tailing characters + // + // DONE-CCC: + // See also, TODO-AAA and TODO-BBB in `xml_fasterxml.c` + // + DEBUG ((DEBUG_VERBOSE, "New CurrentNode, %p\n", CurrentNode)); + if (CurrentNode == NULL) { + DEBUG ((DEBUG_VERBOSE, "At the end of the Root node\n")); + break; + } + + // MS_CHANGE [end] } } else if (Next.State == XTSS_ELEMENT_CLOSE_EMPTY) { DEBUG ((DEBUG_VERBOSE, "XTSS_ELEMENT_CLOSE_EMPTY, empty close\n")); @@ -1115,6 +1130,19 @@ BuildNodeList ( // if (CurrentNode) { CurrentNode = CurrentNode->ParentNode; + DEBUG ((DEBUG_VERBOSE, "New CurrentNode, %p\n", CurrentNode)); + + // MS_CHANGE [begin] + // + // DONE-CCC-2: + // + DEBUG ((DEBUG_VERBOSE, "New CurrentNode, %p\n", CurrentNode)); + if (CurrentNode == NULL) { + DEBUG ((DEBUG_VERBOSE, "At the end of the Root node\n")); + break; + } + + // MS_CHANGE [end] } } diff --git a/XmlSupportPkg/Library/XmlTreeLib/fasterxml/xml_fasterxml.c b/XmlSupportPkg/Library/XmlTreeLib/fasterxml/xml_fasterxml.c index 5fe8c6b3b5..d5953c09dd 100644 --- a/XmlSupportPkg/Library/XmlTreeLib/fasterxml/xml_fasterxml.c +++ b/XmlSupportPkg/Library/XmlTreeLib/fasterxml/xml_fasterxml.c @@ -2700,6 +2700,22 @@ RtlXmlNextToken ( pToken->fError = TRUE; return success; } + // MS_CHANGE + // + // TODO-BBB: See TODO-AAA + // + // if (pRawToken->TokenName == NTXML_RAWTOKEN_ERROR) { + // pToken->fError = TRUE; + // success = EFI_ABORTED; + // return success; + // } + // + // Why TODO? + // If we turn on this, we will be endless on other place.. + // + // Work around? + // See DONE-CCC in `XmlTreeLib.c` + // cbTotalTokenLength = pRawToken->Run.cbData; @@ -2946,6 +2962,14 @@ RtlXmlNextToken ( cbTotalTokenLength = pRawToken->Run.cbData; + // MS_CHANGE + // + // TODO-AAA: + // if we encounter a NTXML_RAWTOKEN_ERROR, + // we will run into endless XTSS_STREAM_HYPERSPACE + // + // DEBUG ((DEBUG_VERBOSE, "pRawToken->TokenName = %d\n", pRawToken->TokenName)); + NextState = XTSS_STREAM_HYPERSPACE; } diff --git a/XmlSupportPkg/Test/UnitTest/XmlTreeLib/TestData.h b/XmlSupportPkg/Test/UnitTest/XmlTreeLib/TestData.h index 8aec694ac0..914944c7e1 100644 --- a/XmlSupportPkg/Test/UnitTest/XmlTreeLib/TestData.h +++ b/XmlSupportPkg/Test/UnitTest/XmlTreeLib/TestData.h @@ -42,6 +42,47 @@ typedef struct { XmlNode *Node; } XmlTestContext; +CONST CHAR8 VerySimpleElementsOnly1[] = + "" + "" + "abcd-1" + ""; + +CONST CHAR8 VerySimpleElementsOnly2[] = + "" + ""; + +CONST CHAR8 VerySimpleElementsOnly3[] = + "" + "" + "abcd-3" + "\r\n\xcd\xcd"; + +CONST CHAR8 VerySimpleElementsOnly4[] = + "" + "\r\n\xcd\xcd"; + +CONST CHAR8 VerySimpleElementsOnly5[] = + "" + "" + "abcd-5" + "" + "" + "xyz-5" + ""; + +CONST CHAR8 VerySimpleElementsOnly6[] = + "" + "" + ""; + +XmlTestContext VerySimpleElementsOnly1Context = { 1, 0, 1, 0, VerySimpleElementsOnly1, NULL, NULL }; +XmlTestContext VerySimpleElementsOnly2Context = { 1, 0, 1, 0, VerySimpleElementsOnly2, NULL, NULL }; +XmlTestContext VerySimpleElementsOnly3Context = { 1, 0, 1, 0, VerySimpleElementsOnly3, NULL, NULL }; +XmlTestContext VerySimpleElementsOnly4Context = { 1, 0, 1, 0, VerySimpleElementsOnly4, NULL, NULL }; +XmlTestContext VerySimpleElementsOnly5Context = { 1, 0, 1, 0, VerySimpleElementsOnly5, NULL, NULL }; +XmlTestContext VerySimpleElementsOnly6Context = { 1, 0, 1, 0, VerySimpleElementsOnly6, NULL, NULL }; + CONST CHAR8 SimpleElementsOnly[] = "" "" diff --git a/XmlSupportPkg/Test/UnitTest/XmlTreeLib/XmlTreeLibUnitTests.c b/XmlSupportPkg/Test/UnitTest/XmlTreeLib/XmlTreeLibUnitTests.c index d194a8ba2c..85a0850f13 100644 --- a/XmlSupportPkg/Test/UnitTest/XmlTreeLib/XmlTreeLibUnitTests.c +++ b/XmlSupportPkg/Test/UnitTest/XmlTreeLib/XmlTreeLibUnitTests.c @@ -521,6 +521,13 @@ UnitTestingEntry ( goto EXIT; } + AddTestCase (InputTestSuite, "Parse Valid XML with a very simple root", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly1Context); + AddTestCase (InputTestSuite, "Parse Valid XML with a very simple empty tag root", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly2Context); + AddTestCase (InputTestSuite, "Parse Valid XML with a very simple root, tailing with uninitialized memory", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly3Context); + AddTestCase (InputTestSuite, "Parse Valid XML with a very simple empty tag root, tailing with uninitialized memory", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly4Context); + AddTestCase (InputTestSuite, "Parse Valid XML with two very simple roots, report only first root", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly5Context); + AddTestCase (InputTestSuite, "Parse Valid XML with two very simple empty tag roots, report only first root", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly6Context); + AddTestCase (InputTestSuite, "Parse Valid XML with simple elements 3 layers", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &SimpleElementsOnlyContext); AddTestCase (InputTestSuite, "Parse Valid XML with 2 elements and 2 attributes", "ValidElementsAndAttributes", ParseValidXml, NULL, CleanUpXmlTestContext, &SimpleElementsAttributesContext); AddTestCase (InputTestSuite, "Parse Invalid XML string containing an attribute with invalid xml chars", "NonXmlEncodedAttribute", ParseValidXml, NULL, CleanUpXmlTestContext, &NonEncodedXmlAttribute1Context);