RootShell: fix off by one

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-01-08 20:41:36 +01:00
parent 5944efc13c
commit 1ae10b8f45

View File

@ -13,7 +13,6 @@ import java.io.BufferedReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -29,10 +28,6 @@ import javax.inject.Inject;
@ApplicationScope @ApplicationScope
public class RootShell { public class RootShell {
private static final Pattern ERRNO_EXTRACTOR = Pattern.compile("error=(\\d+)"); 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 TAG = "WireGuard/" + RootShell.class.getSimpleName();
private static final String[][] libraryNamedExecutables = { private static final String[][] libraryNamedExecutables = {
{"libwg.so", "wg"}, {"libwg.so", "wg"},
@ -179,7 +174,7 @@ public class RootShell {
++beginEnds; ++beginEnds;
continue; 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)); errnoStdout = Integer.valueOf(line.substring(end.length() + 1));
++beginEnds; ++beginEnds;
break; break;
@ -197,7 +192,7 @@ public class RootShell {
++beginEnds; ++beginEnds;
continue; 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)); errnoStderr = Integer.valueOf(line.substring(end.length() + 1));
++beginEnds; ++beginEnds;
break; break;