From 4e0a769227fa185ffbfdf6bf68b67294868b8851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 4 Apr 2022 11:44:10 +0200 Subject: [PATCH] [SUREFIRE-2056] Reproduce buffer overflow in EventChannelEncoder when the test ID is null --- .../booter/spi/EventChannelEncoderTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/spi/EventChannelEncoderTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/spi/EventChannelEncoderTest.java index 5b28d3a13a..d7f1e29e67 100644 --- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/spi/EventChannelEncoderTest.java +++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/spi/EventChannelEncoderTest.java @@ -1226,6 +1226,25 @@ public void testStdErrStreamLn() throws IOException .isEqualTo( expected ); } + @Test + public void testStdErrStreamNullTestId() throws IOException + { + Stream out = Stream.newStream(); + WritableBufferedByteChannel channel = newBufferedChannel( out ); + EventChannelEncoder encoder = new EventChannelEncoder( channel ); + + encoder.testOutput( new TestOutputReportEntry( stdErr( "" ), NORMAL_RUN, null ) ); + channel.close(); + + String expected = ":maven-surefire-event:\u000e:std-err-stream:" + + (char) 10 + ":normal-run:\u0000:" + + "\u0005:UTF-8:\u0000\u0000\u0000\u0000::"; + + assertThat( new String( out.toByteArray(), UTF_8 ) ) + .isEqualTo( expected ); + } + + @Test @SuppressWarnings( "checkstyle:innerassignment" ) public void shouldCountSameNumberOfSystemProperties() throws IOException