aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-22 15:04:54 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-22 15:05:22 +0200
commit890b31638622d8ba9d5501e57cb4119066cfc57a (patch)
tree5299bf4f2d93131810b72560931b68a76ded868c
parentToolsInstaller: write to temporary file, fsync, rename (diff)
downloadwireguard-android-master.tar.xz
wireguard-android-master.zip
ModuleLoader: sync file before renamingHEADmaster
-rw-r--r--app/src/main/java/com/wireguard/android/util/ModuleLoader.java4
1 files changed, 2 insertions, 2 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/ModuleLoader.java b/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
index 524d10a..f5bca0f 100644
--- a/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
+++ b/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
@@ -22,7 +22,6 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
@@ -159,7 +158,7 @@ public class ModuleLoader {
tempFile = File.createTempFile("UNVERIFIED-", null, tmpDir);
MessageDigest digest = MessageDigest.getInstance("SHA-256");
try (final InputStream inputStream = connection.getInputStream();
- final OutputStream outputStream = new FileOutputStream(tempFile)) {
+ final FileOutputStream outputStream = new FileOutputStream(tempFile)) {
int total = 0;
while ((len = inputStream.read(input)) > 0) {
total += len;
@@ -168,6 +167,7 @@ public class ModuleLoader {
outputStream.write(input, 0, len);
digest.update(input, 0, len);
}
+ outputStream.getFD().sync();
}
if (!Arrays.equals(digest.digest(), modules.get(moduleName).bytes))
throw new IOException("Incorrect file hash");