From 16890a659e6d7877b86e870fe4f0ef9cc19aee5b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 22 Oct 2019 15:04:54 +0200 Subject: ModuleLoader: sync file before renaming Signed-off-by: Jason A. Donenfeld --- app/src/main/java/com/wireguard/android/util/ModuleLoader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/com/wireguard/android') 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 524d10a6..f5bca0f2 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"); -- cgit v1.2.3