-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #889 from spyrkob/UNDERTOW-1657
[UNDERTOW-1657] Memory exhaustion issue in HttpReadListener and related fixes
- Loading branch information
Showing
11 changed files
with
374 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...ava/io/undertow/server/handlers/HttpContinueConduitWrappingHandlerBufferLeakTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2020 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.undertow.server.handlers; | ||
|
||
import java.io.IOException; | ||
import java.net.Socket; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.junit.Assume; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.undertow.server.HttpHandler; | ||
import io.undertow.server.HttpServerExchange; | ||
import io.undertow.testutils.DefaultServer; | ||
import io.undertow.util.StatusCodes; | ||
|
||
/** | ||
* @author Stuart Douglas | ||
*/ | ||
@RunWith(DefaultServer.class) | ||
public class HttpContinueConduitWrappingHandlerBufferLeakTestCase { | ||
|
||
static Socket persistentSocket; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
final BlockingHandler blockingHandler = new BlockingHandler(); | ||
final HttpContinueReadHandler handler = new HttpContinueReadHandler(blockingHandler); | ||
DefaultServer.setRootHandler(handler); | ||
blockingHandler.setRootHandler(new HttpHandler() { | ||
@Override | ||
public void handleRequest(final HttpServerExchange exchange) { | ||
try { | ||
if (exchange.getQueryParameters().containsKey("reject")) { | ||
exchange.getRequestChannel(); | ||
exchange.setStatusCode(StatusCodes.EXPECTATION_FAILED); | ||
exchange.getOutputStream().close(); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Before | ||
public void before() { | ||
Assume.assumeFalse(DefaultServer.isAjp()); | ||
} | ||
|
||
@Test | ||
public void testHttpContinueRejectedBodySentAnywayNoBufferLeak() throws IOException { | ||
persistentSocket = new Socket(DefaultServer.getHostAddress(), DefaultServer.getHostPort()); | ||
|
||
String message = "POST /path?reject=true HTTP/1.1\r\n" + | ||
"Expect: 100-continue\r\n" + | ||
"Content-Length: 16\r\n" + | ||
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + | ||
"Host: localhost:7777\r\n" + | ||
"Connection: Keep-Alive\r\n\r\nMy HTTP Request!"; | ||
persistentSocket.getOutputStream().write(message.getBytes(StandardCharsets.UTF_8)); | ||
persistentSocket.getOutputStream().flush(); | ||
persistentSocket.getInputStream().read(); | ||
} | ||
|
||
@Test | ||
public void testHttpContinueBodySentAnywayNoLeak() throws IOException { | ||
persistentSocket = new Socket(DefaultServer.getHostAddress(), DefaultServer.getHostPort()); | ||
|
||
String message = "POST /path HTTP/1.1\r\n" + | ||
"Expect: 100-continue\r\n" + | ||
"Content-Length: 16\r\n" + | ||
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + | ||
"Host: localhost:7777\r\n" + | ||
"Connection: Keep-Alive\r\n\r\nMy HTTP Request!"; | ||
persistentSocket.getOutputStream().write(message.getBytes(StandardCharsets.UTF_8)); | ||
persistentSocket.getOutputStream().flush(); | ||
persistentSocket.getInputStream().read(); | ||
} | ||
|
||
} |
Oops, something went wrong.