Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f86ca6d

Browse files
Protect readLine() against DoS (#7)
Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
1 parent 54e748a commit f86ca6d

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.netflix.appinfo;
1818

19+
import io.github.pixee.security.BoundedLineReader;
1920
import java.io.BufferedReader;
2021
import java.io.IOException;
2122
import java.io.InputStream;
@@ -115,7 +116,7 @@ public String read(InputStream inputStream) throws IOException {
115116
try {
116117
String toReturn = null;
117118
String inputLine;
118-
while ((inputLine = br.readLine()) != null) {
119+
while ((inputLine = BoundedLineReader.readLine(br, 5_000_000)) != null) {
119120
Matcher matcher = pattern.matcher(inputLine);
120121
if (toReturn == null && matcher.find()) {
121122
toReturn = matcher.group(1);
@@ -155,11 +156,11 @@ public String read(InputStream inputStream) throws IOException {
155156
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
156157
String toReturn;
157158
try {
158-
String line = br.readLine();
159+
String line = BoundedLineReader.readLine(br, 5_000_000);
159160
toReturn = line;
160161

161162
while (line != null) { // need to read all the buffer for a clean connection close
162-
line = br.readLine();
163+
line = BoundedLineReader.readLine(br, 5_000_000);
163164
}
164165

165166
return toReturn;

eureka-client/src/main/java/com/netflix/discovery/internal/util/AmazonInfoUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.netflix.discovery.internal.util;
22

33
import com.netflix.appinfo.AmazonInfo.MetaDataKey;
4+
import io.github.pixee.security.BoundedLineReader;
45

56
import java.io.BufferedReader;
67
import java.io.IOException;
@@ -24,7 +25,7 @@ public static String readEc2MetadataUrl(MetaDataKey metaDataKey, URL url, int co
2425
if (uc.getResponseCode() != HttpURLConnection.HTTP_OK) { // need to read the error for clean connection close
2526
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getErrorStream()));
2627
try {
27-
while (br.readLine() != null) {
28+
while (BoundedLineReader.readLine(br, 5_000_000) != null) {
2829
// do nothing but keep reading the line
2930
}
3031
} finally {

eureka-examples/src/main/java/com/netflix/eureka/ExampleEurekaClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.netflix.eureka;
1818

19+
import io.github.pixee.security.BoundedLineReader;
1920
import java.io.BufferedReader;
2021
import java.io.IOException;
2122
import java.io.InputStreamReader;
@@ -103,7 +104,7 @@ public void sendRequestToServiceUsingEureka(EurekaClient eurekaClient) {
103104

104105
System.out.println("Waiting for server response..");
105106
BufferedReader rd = new BufferedReader(new InputStreamReader(s.getInputStream()));
106-
String str = rd.readLine();
107+
String str = BoundedLineReader.readLine(rd, 5_000_000);
107108
if (str != null) {
108109
System.out.println("Received response from server: " + str);
109110
System.out.println("Exiting the client. Demo over..");

eureka-examples/src/main/java/com/netflix/eureka/ExampleServiceBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.netflix.appinfo.InstanceInfo;
55
import com.netflix.config.DynamicPropertyFactory;
66
import com.netflix.discovery.EurekaClient;
7+
import io.github.pixee.security.BoundedLineReader;
78

89
import javax.annotation.PostConstruct;
910
import javax.annotation.PreDestroy;
@@ -106,7 +107,7 @@ private void waitForRegistrationWithEureka(EurekaClient eurekaClient) {
106107
private void processRequest(final Socket s) {
107108
try {
108109
BufferedReader rd = new BufferedReader(new InputStreamReader(s.getInputStream()));
109-
String line = rd.readLine();
110+
String line = BoundedLineReader.readLine(rd, 5_000_000);
110111
if (line != null) {
111112
System.out.println("Received a request from the example client: " + line);
112113
}

0 commit comments

Comments
 (0)