aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-21 18:55:35 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-21 18:56:28 +0200
commit674fd2eed8794e31be048aaffde80ca24d6f5874 (patch)
treee2813f57f6051ab431d054abcd4f04eabbc674bb
parentlibwg-go: version bump (diff)
downloadwireguard-android-674fd2eed8794e31be048aaffde80ca24d6f5874.tar.xz
wireguard-android-674fd2eed8794e31be048aaffde80ca24d6f5874.zip
ToolsInstaller: write to temporary file, fsync, rename
Reported-by: Andre Christanto <christantoandre@gmail.com>
-rw-r--r--app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java1
-rw-r--r--app/src/main/java/com/wireguard/android/util/ToolsInstaller.java10
2 files changed, 8 insertions, 3 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java b/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
index e3923d1..428c5a2 100644
--- a/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
+++ b/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
@@ -54,6 +54,7 @@ public final class SharedLibraryLoader {
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
+ out.getFD().sync();
}
return true;
}
diff --git a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
index defdefd..82d1e94 100644
--- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
+++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
@@ -149,18 +149,22 @@ public final class ToolsInstaller {
public boolean extract() throws IOException {
localBinaryDir.mkdirs();
final File files[] = new File[EXECUTABLES.length];
+ final File tempFiles[] = new File[EXECUTABLES.length];
boolean allExist = true;
for (int i = 0; i < files.length; ++i) {
files[i] = new File(localBinaryDir, EXECUTABLES[i]);
+ tempFiles[i] = new File(localBinaryDir, EXECUTABLES[i] + ".tmp");
allExist &= files[i].exists();
}
if (allExist)
return false;
for (int i = 0; i < files.length; ++i) {
- if (!SharedLibraryLoader.extractLibrary(context, EXECUTABLES[i], files[i]))
+ if (!SharedLibraryLoader.extractLibrary(context, EXECUTABLES[i], tempFiles[i]))
throw new FileNotFoundException("Unable to find " + EXECUTABLES[i]);
- if (!files[i].setExecutable(true, false))
- throw new IOException("Unable to mark " + files[i].getAbsolutePath() + " as executable");
+ if (!tempFiles[i].setExecutable(true, false))
+ throw new IOException("Unable to mark " + tempFiles[i].getAbsolutePath() + " as executable");
+ if (!tempFiles[i].renameTo(files[i]))
+ throw new IOException("Unable to rename " + tempFiles[i].getAbsolutePath() + " to " + files[i].getAbsolutePath());
}
return true;
}