From 1ae10b8f45713b92cf6082dcb00ece6c58eda225 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 8 Jan 2018 20:41:36 +0100 Subject: RootShell: fix off by one Signed-off-by: Jason A. Donenfeld --- app/src/main/java/com/wireguard/android/util/RootShell.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/wireguard/android/util/RootShell.java b/app/src/main/java/com/wireguard/android/util/RootShell.java index 205dd956..116fbd2c 100644 --- a/app/src/main/java/com/wireguard/android/util/RootShell.java +++ b/app/src/main/java/com/wireguard/android/util/RootShell.java @@ -13,7 +13,6 @@ import java.io.BufferedReader; import java.io.OutputStreamWriter; import java.io.InputStreamReader; import java.io.File; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.UUID; @@ -29,10 +28,6 @@ import javax.inject.Inject; @ApplicationScope public class RootShell { private static final Pattern ERRNO_EXTRACTOR = Pattern.compile("error=(\\d+)"); - /** - * Setup commands that are run at the beginning of each root shell. The trap command ensures - * access to the return value of the last command, since su itself always exits with 0. - */ private static final String TAG = "WireGuard/" + RootShell.class.getSimpleName(); private static final String[][] libraryNamedExecutables = { {"libwg.so", "wg"}, @@ -179,7 +174,7 @@ public class RootShell { ++beginEnds; continue; } - if (line.startsWith(end) && line.length() > end.length()) { + if (line.startsWith(end) && line.length() > end.length() + 1) { errnoStdout = Integer.valueOf(line.substring(end.length() + 1)); ++beginEnds; break; @@ -197,7 +192,7 @@ public class RootShell { ++beginEnds; continue; } - if (line.startsWith(end) && line.length() > end.length()) { + if (line.startsWith(end) && line.length() > end.length() + 1) { errnoStderr = Integer.valueOf(line.substring(end.length() + 1)); ++beginEnds; break; -- cgit v1.2.3