mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-24 06:51:17 +01:00
Merge pull request #10425 from JosJuice/android-import-path-traversal
Android: Fix path traversal when importing user data
This commit is contained in:
commit
5e59561637
@ -19,6 +19,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||||||
|
|
||||||
import org.dolphinemu.dolphinemu.R;
|
import org.dolphinemu.dolphinemu.R;
|
||||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
||||||
|
import org.dolphinemu.dolphinemu.utils.Log;
|
||||||
import org.dolphinemu.dolphinemu.utils.ThreadUtil;
|
import org.dolphinemu.dolphinemu.utils.ThreadUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -185,6 +186,7 @@ public class UserDataActivity extends AppCompatActivity
|
|||||||
try (ZipInputStream zis = new ZipInputStream(is))
|
try (ZipInputStream zis = new ZipInputStream(is))
|
||||||
{
|
{
|
||||||
File userDirectory = new File(DirectoryInitialization.getUserDirectory());
|
File userDirectory = new File(DirectoryInitialization.getUserDirectory());
|
||||||
|
String userDirectoryCanonicalized = userDirectory.getCanonicalPath() + '/';
|
||||||
|
|
||||||
sMustRestartApp = true;
|
sMustRestartApp = true;
|
||||||
deleteChildrenRecursively(userDirectory);
|
deleteChildrenRecursively(userDirectory);
|
||||||
@ -198,6 +200,12 @@ public class UserDataActivity extends AppCompatActivity
|
|||||||
File destFile = new File(userDirectory, ze.getName());
|
File destFile = new File(userDirectory, ze.getName());
|
||||||
File destDirectory = ze.isDirectory() ? destFile : destFile.getParentFile();
|
File destDirectory = ze.isDirectory() ? destFile : destFile.getParentFile();
|
||||||
|
|
||||||
|
if (!destFile.getCanonicalPath().startsWith(userDirectoryCanonicalized))
|
||||||
|
{
|
||||||
|
Log.error("Zip file attempted path traversal! " + ze.getName());
|
||||||
|
return R.string.user_data_import_failure;
|
||||||
|
}
|
||||||
|
|
||||||
if (!destDirectory.isDirectory() && !destDirectory.mkdirs())
|
if (!destDirectory.isDirectory() && !destDirectory.mkdirs())
|
||||||
{
|
{
|
||||||
throw new IOException("Failed to create directory " + destDirectory);
|
throw new IOException("Failed to create directory " + destDirectory);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user