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

Commit eeefbe07 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Add a little protection to prevent file opens when shell is done."

parents 857a8910 e5ed1999
Loading
Loading
Loading
Loading
+12 −1
Original line number Original line Diff line number Diff line
@@ -56,12 +56,18 @@ typedef UniquePtr<char[], SecurityContext_Delete> Unique_SecurityContext;
class MyShellCallback : public BnShellCallback
class MyShellCallback : public BnShellCallback
{
{
public:
public:
    bool mActive = true;

    virtual int openOutputFile(const String16& path, const String16& seLinuxContext) {
    virtual int openOutputFile(const String16& path, const String16& seLinuxContext) {
        String8 path8(path);
        String8 path8(path);
        char cwd[256];
        char cwd[256];
        getcwd(cwd, 256);
        getcwd(cwd, 256);
        String8 fullPath(cwd);
        String8 fullPath(cwd);
        fullPath.appendPath(path8);
        fullPath.appendPath(path8);
        if (!mActive) {
            aerr << "Open attempt after active for: " << fullPath << endl;
            return -EPERM;
        }
        int fd = open(fullPath.string(), O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG);
        int fd = open(fullPath.string(), O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG);
        if (fd < 0) {
        if (fd < 0) {
            return fd;
            return fd;
@@ -136,8 +142,13 @@ int main(int argc, char* const argv[])
        return 20;
        return 20;
    }
    }


    sp<MyShellCallback> cb = new MyShellCallback();

    // TODO: block until a result is returned to MyResultReceiver.
    // TODO: block until a result is returned to MyResultReceiver.
    IBinder::shellCommand(service, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, args,
    IBinder::shellCommand(service, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, args,
            new MyShellCallback(), new MyResultReceiver());
            cb, new MyResultReceiver());

    cb->mActive = false;

    return 0;
    return 0;
}
}