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

Commit a5cee93b authored by Yifan Hong's avatar Yifan Hong
Browse files

fastbootd: add O_CLOEXEC/O_BINARY for OpenPartition

O_CLOEXEC ensures fastbootd does not leak fds to the parent
process (recovery).

O_BINARY has no effect in Linux, but it is explicit that
the file (partition) to read is a binary file.

Test: pass
Bug: 173654501

Change-Id: Idba922965ce666af1b7ee460ec7449fabd511c35
parent c4073d3e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -90,7 +90,8 @@ bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHan
        return false;
    }

    int flags = O_EXCL | (read ? O_RDONLY : O_WRONLY);
    int flags = (read ? O_RDONLY : O_WRONLY);
    flags |= (O_EXCL | O_CLOEXEC | O_BINARY);
    unique_fd fd(TEMP_FAILURE_RETRY(open(handle->path().c_str(), flags)));
    if (fd < 0) {
        PLOG(ERROR) << "Failed to open block device: " << handle->path();