소스 검색

ToolsInstaller: write to temporary file, fsync, rename

Reported-by: Andre Christanto <christantoandre@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
master
Jason A. Donenfeld 4 년 전
부모
커밋
d40ac7f89d
2개의 변경된 파일8개의 추가작업 그리고 3개의 파일을 삭제
  1. +1
    -0
      app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
  2. +7
    -3
      app/src/main/java/com/wireguard/android/util/ToolsInstaller.java

+ 1
- 0
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;
}


+ 7
- 3
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;
}


불러오는 중...
취소
저장