From b9d7161fce642c218defc3af59694dc073d266ce Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Mon, 28 Dec 2020 23:55:02 -0300 Subject: [PATCH] Fixed infinite loop in MXParser and reactivate tests in MXParserTest (#118) --- .../org/codehaus/plexus/util/xml/pull/MXParser.java | 11 +++++++++++ .../codehaus/plexus/util/xml/pull/MXParserTest.java | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java index a612e6be..40a12a21 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java +++ b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java @@ -3044,6 +3044,7 @@ private boolean parsePI() try { boolean seenPITarget = false; + boolean seenInnerTag = false; boolean seenQ = false; char ch = more(); if ( isS( ch ) ) @@ -3077,6 +3078,16 @@ else if ( ch == '>' ) throw new XmlPullParserException( "processing instruction PITarget name not found", this, null ); } + else if ( !seenInnerTag ) + { + // seenPITarget && !seenQ + throw new XmlPullParserException( "processing instruction started on line " + curLine + + " and column " + curColumn + " was not closed", this, null ); + } + } + else if ( ch == '<' ) + { + seenInnerTag = true; } else { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 5b685e8e..0cb9c061 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -413,6 +413,7 @@ public void testLargeText_NoOverflow() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + @Test public void testMalformedProcessingInstructionAfterTag() throws Exception { @@ -438,6 +439,7 @@ public void testMalformedProcessingInstructionAfterTag() } } + @Test public void testMalformedProcessingInstructionBeforeTag() throws Exception { @@ -463,6 +465,7 @@ public void testMalformedProcessingInstructionBeforeTag() } } + @Test public void testMalformedProcessingInstructionSpaceBeforeName() throws Exception { @@ -490,6 +493,7 @@ public void testMalformedProcessingInstructionSpaceBeforeName() } } + @Test public void testMalformedProcessingInstructionNoClosingQuestionMark() throws Exception { @@ -517,6 +521,7 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark() } } + @Test public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() throws Exception { @@ -544,6 +549,7 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() } } + @Test public void testMalformedXMLRootElement() throws Exception { @@ -564,6 +570,7 @@ public void testMalformedXMLRootElement() } } + @Test public void testMalformedXMLRootElement2() throws Exception { @@ -584,6 +591,7 @@ public void testMalformedXMLRootElement2() } } + @Test public void testMalformedXMLRootElement3() throws Exception { @@ -605,6 +613,7 @@ public void testMalformedXMLRootElement3() } } + @Test public void testMalformedXMLRootElement4() throws Exception { @@ -628,6 +637,7 @@ public void testMalformedXMLRootElement4() } } + @Test public void testMalformedXMLRootElement5() throws Exception {