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

Commit 99f3772c authored by Hridya Valsaraju's avatar Hridya Valsaraju
Browse files

Validate partition name when searching for physical partitions.

Bug: 117274137
Test: fastboot getvar has-slot:../by-name/system
Change-Id: Ibc74a12f836a30bdf1fd7f6b2a1e941de2430c70
parent f3186de1
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@


#include <android-base/file.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
#include <fs_mgr.h>
#include <fs_mgr.h>
#include <fs_mgr_dm_linear.h>
#include <fs_mgr_dm_linear.h>
#include <liblp/liblp.h>
#include <liblp/liblp.h>
@@ -82,6 +83,10 @@ bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHan
}
}


std::optional<std::string> FindPhysicalPartition(const std::string& name) {
std::optional<std::string> FindPhysicalPartition(const std::string& name) {
    // Check for an invalid file name
    if (android::base::StartsWith(name, "../") || name.find("/../") != std::string::npos) {
        return {};
    }
    std::string path = "/dev/block/by-name/" + name;
    std::string path = "/dev/block/by-name/" + name;
    if (access(path.c_str(), W_OK) < 0) {
    if (access(path.c_str(), W_OK) < 0) {
        return {};
        return {};