aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/android/util
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-09 09:17:08 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-09 09:17:08 -0600
commitca077dd090b5b6ec587e48154dbdb17570d8bf57 (patch)
tree9159d723ed63ceb34c918896a17e17519aa0a91b /app/src/main/java/com/wireguard/android/util
parentRootShell: Be stricter about command delimiters (diff)
downloadwireguard-android-ca077dd090b5b6ec587e48154dbdb17570d8bf57.tar.xz
wireguard-android-ca077dd090b5b6ec587e48154dbdb17570d8bf57.zip
RootShell: Improve shell start error handling
No need to catch and re-throw exceptions before starting the process. If running `su` itself fails, there's no (functional) root, so report that. Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/util')
-rw-r--r--app/src/main/java/com/wireguard/android/util/RootShell.java23
1 files changed, 14 insertions, 9 deletions
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 1e00020f..7fbafa33 100644
--- a/app/src/main/java/com/wireguard/android/util/RootShell.java
+++ b/app/src/main/java/com/wireguard/android/util/RootShell.java
@@ -123,18 +123,23 @@ public class RootShell {
}
public synchronized void start() throws IOException, NoRootException {
+ if (isRunning())
+ return;
+ if (!localBinaryDir.isDirectory() && !localBinaryDir.mkdirs())
+ throw new FileNotFoundException("Could not create local binary directory");
+ if (!localTemporaryDir.isDirectory() && !localTemporaryDir.mkdirs())
+ throw new FileNotFoundException("Could not create local temporary directory");
+ if (!isExecutableInPath(SU))
+ throw new NoRootException(deviceNotRootedMessage);
try {
- if (isRunning())
- return;
- if (!localBinaryDir.isDirectory() && !localBinaryDir.mkdirs())
- throw new FileNotFoundException("Could not create local binary directory");
- if (!localTemporaryDir.isDirectory() && !localTemporaryDir.mkdirs())
- throw new FileNotFoundException("Could not create local temporary directory");
- if (!isExecutableInPath(SU))
- throw new NoRootException(deviceNotRootedMessage);
final ProcessBuilder builder = new ProcessBuilder().command(SU);
builder.environment().put("LC_ALL", "C");
- process = builder.start();
+ try {
+ process = builder.start();
+ } catch (final IOException e) {
+ // A failure at this stage means the device isn't rooted.
+ throw new NoRootException(deviceNotRootedMessage, e);
+ }
stdin = new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8);
stdout = new BufferedReader(new InputStreamReader(process.getInputStream(),
StandardCharsets.UTF_8));