Skip to content

Protect readLine() against DoS #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions buildSrc/src/main/groovy/ShellUtils.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io.github.pixee.security.BoundedLineReader;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -156,15 +157,15 @@ public static CommandResult execCmd(final String[] commands,
new InputStreamReader(process.getErrorStream(), "UTF-8")
);
String line;
if ((line = successResult.readLine()) != null) {
if ((line = BoundedLineReader.readLine(successResult, 5_000_000)) != null) {
successMsg.append(line);
while ((line = successResult.readLine()) != null) {
while ((line = BoundedLineReader.readLine(successResult, 5_000_000)) != null) {
successMsg.append(LINE_SEP).append(line);
}
}
if ((line = errorResult.readLine()) != null) {
if ((line = BoundedLineReader.readLine(errorResult, 5_000_000)) != null) {
errorMsg.append(line);
while ((line = errorResult.readLine()) != null) {
while ((line = BoundedLineReader.readLine(errorResult, 5_000_000)) != null) {
errorMsg.append(LINE_SEP).append(line);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.blankj.utilcode.constant.MemoryConstants;
import com.blankj.utilcode.constant.TimeConstants;
import io.github.pixee.security.BoundedLineReader;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -684,7 +685,7 @@ public static List<String> inputStream2Lines(final InputStream is,
List<String> list = new ArrayList<>();
reader = new BufferedReader(new InputStreamReader(is, getSafeCharset(charsetName)));
String line;
while ((line = reader.readLine()) != null) {
while ((line = BoundedLineReader.readLine(reader, 5_000_000)) != null) {
list.add(line);
}
return list;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.blankj.utilcode.util;

import android.util.Log;
import io.github.pixee.security.BoundedLineReader;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
Expand Down Expand Up @@ -679,7 +680,7 @@ public static List<String> readFile2List(final File file,
new InputStreamReader(new FileInputStream(file), charsetName)
);
}
while ((line = reader.readLine()) != null) {
while ((line = BoundedLineReader.readLine(reader, 5_000_000)) != null) {
if (curLine > end) break;
if (st <= curLine && curLine <= end) list.add(line);
++curLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.support.annotation.RequiresPermission;
import android.text.TextUtils;
import android.util.Log;
import io.github.pixee.security.BoundedLineReader;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -221,7 +222,7 @@ private static String getCurrentProcessNameByFile() {
try {
File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline");
BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
String processName = mBufferedReader.readLine().trim();
String processName = BoundedLineReader.readLine(mBufferedReader, 5_000_000).trim();
mBufferedReader.close();
return processName;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import io.github.pixee.security.BoundedLineReader;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -398,7 +399,7 @@ private static String getSystemPropertyByShell(final String propName) {
try {
Process p = Runtime.getRuntime().exec("getprop " + propName);
input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
String ret = input.readLine();
String ret = BoundedLineReader.readLine(input, 5_000_000);
if (ret != null) {
return ret;
}
Expand Down Expand Up @@ -453,4 +454,4 @@ public String toString() {
", version=" + version + "}";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.blankj.utilcode.util;

import android.support.annotation.NonNull;
import io.github.pixee.security.BoundedLineReader;

import java.io.BufferedReader;
import java.io.DataOutputStream;
Expand Down Expand Up @@ -228,15 +229,15 @@ public static CommandResult execCmd(final String[] commands,
new InputStreamReader(process.getErrorStream(), "UTF-8")
);
String line;
if ((line = successResult.readLine()) != null) {
if ((line = BoundedLineReader.readLine(successResult, 5_000_000)) != null) {
successMsg.append(line);
while ((line = successResult.readLine()) != null) {
while ((line = BoundedLineReader.readLine(successResult, 5_000_000)) != null) {
successMsg.append(LINE_SEP).append(line);
}
}
if ((line = errorResult.readLine()) != null) {
if ((line = BoundedLineReader.readLine(errorResult, 5_000_000)) != null) {
errorMsg.append(line);
while ((line = errorResult.readLine()) != null) {
while ((line = BoundedLineReader.readLine(errorResult, 5_000_000)) != null) {
errorMsg.append(LINE_SEP).append(line);
}
}
Expand Down