Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88b91d39 authored by Marco Nelissen's avatar Marco Nelissen Committed by Android Git Automerger
Browse files

am c8db4536: am 7e51102c: Merge "Validate MTP path" into lmp-dev

* commit 'c8db4536507a87a35d05ea47f9c864eb9deda2d7':
  Validate MTP path
parents dcc0736c e3fafc1d
Loading
Loading
Loading
Loading
+20 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ import android.view.Display;
import android.view.WindowManager;
import android.view.WindowManager;


import java.io.File;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashMap;
import java.util.Locale;
import java.util.Locale;


@@ -300,8 +301,27 @@ public class MtpDatabase {
        return false;
        return false;
    }
    }


    // returns true if the path is in the storage root
    private boolean inStorageRoot(String path) {
        try {
            File f = new File(path);
            String canonical = f.getCanonicalPath();
            if (canonical.startsWith(mMediaStoragePath)) {
                return true;
            }
        } catch (IOException e) {
            // ignore
        }
        return false;
    }

    private int beginSendObject(String path, int format, int parent,
    private int beginSendObject(String path, int format, int parent,
                         int storageId, long size, long modified) {
                         int storageId, long size, long modified) {
        // if the path is outside of the storage root, do not allow access
        if (!inStorageRoot(path)) {
            Log.e(TAG, "attempt to put file outside of storage area: " + path);
            return -1;
        }
        // if mSubDirectories is not null, do not allow copying files to any other locations
        // if mSubDirectories is not null, do not allow copying files to any other locations
        if (!inStorageSubDirectory(path)) return -1;
        if (!inStorageSubDirectory(path)) return -1;