Skip to content

Commit b9d7161

Browse files
committed
Fixed infinite loop in MXParser and reactivate tests in MXParserTest
(codehaus-plexus#118)
1 parent 7e2e788 commit b9d7161

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,6 +3044,7 @@ private boolean parsePI()
30443044
try
30453045
{
30463046
boolean seenPITarget = false;
3047+
boolean seenInnerTag = false;
30473048
boolean seenQ = false;
30483049
char ch = more();
30493050
if ( isS( ch ) )
@@ -3077,6 +3078,16 @@ else if ( ch == '>' )
30773078
throw new XmlPullParserException( "processing instruction PITarget name not found", this,
30783079
null );
30793080
}
3081+
else if ( !seenInnerTag )
3082+
{
3083+
// seenPITarget && !seenQ
3084+
throw new XmlPullParserException( "processing instruction started on line " + curLine
3085+
+ " and column " + curColumn + " was not closed", this, null );
3086+
}
3087+
}
3088+
else if ( ch == '<' )
3089+
{
3090+
seenInnerTag = true;
30803091
}
30813092
else
30823093
{

src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ public void testLargeText_NoOverflow()
413413
assertEquals( XmlPullParser.END_TAG, parser.nextToken() );
414414
}
415415

416+
@Test
416417
public void testMalformedProcessingInstructionAfterTag()
417418
throws Exception
418419
{
@@ -438,6 +439,7 @@ public void testMalformedProcessingInstructionAfterTag()
438439
}
439440
}
440441

442+
@Test
441443
public void testMalformedProcessingInstructionBeforeTag()
442444
throws Exception
443445
{
@@ -463,6 +465,7 @@ public void testMalformedProcessingInstructionBeforeTag()
463465
}
464466
}
465467

468+
@Test
466469
public void testMalformedProcessingInstructionSpaceBeforeName()
467470
throws Exception
468471
{
@@ -490,6 +493,7 @@ public void testMalformedProcessingInstructionSpaceBeforeName()
490493
}
491494
}
492495

496+
@Test
493497
public void testMalformedProcessingInstructionNoClosingQuestionMark()
494498
throws Exception
495499
{
@@ -517,6 +521,7 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark()
517521
}
518522
}
519523

524+
@Test
520525
public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
521526
throws Exception
522527
{
@@ -544,6 +549,7 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
544549
}
545550
}
546551

552+
@Test
547553
public void testMalformedXMLRootElement()
548554
throws Exception
549555
{
@@ -564,6 +570,7 @@ public void testMalformedXMLRootElement()
564570
}
565571
}
566572

573+
@Test
567574
public void testMalformedXMLRootElement2()
568575
throws Exception
569576
{
@@ -584,6 +591,7 @@ public void testMalformedXMLRootElement2()
584591
}
585592
}
586593

594+
@Test
587595
public void testMalformedXMLRootElement3()
588596
throws Exception
589597
{
@@ -605,6 +613,7 @@ public void testMalformedXMLRootElement3()
605613
}
606614
}
607615

616+
@Test
608617
public void testMalformedXMLRootElement4()
609618
throws Exception
610619
{
@@ -628,6 +637,7 @@ public void testMalformedXMLRootElement4()
628637
}
629638
}
630639

640+
@Test
631641
public void testMalformedXMLRootElement5()
632642
throws Exception
633643
{

0 commit comments

Comments
 (0)