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

Commit e60c029f authored by Aaron Knobloch's avatar Aaron Knobloch
Browse files

Avoid clobbering `errno` from `realpath` call in `__mount`

The __mount logic calls `realpath`, which can set errno in some cases (e.g. if a file is not found or the input string is malformed). The __mount algorithm here is attempting to use errno as signal of the `mount` syscall's success, which is not accurate if the value is clobbered.

This CL fixes the issue by clearing the errno explicitly just before the `mount` call. This ensures that any errno set is from the `mount` call itself. The existing `save_errno` field handles the logic for reading the previous invocation's errno value.

Bug: b/379929394
Change-Id: I840171079a71a1e7927fcc30d6c0863fab6c7e00
parent 3fa729d1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -858,6 +858,10 @@ static int __mount(const std::string& source, const std::string& target, const F
        if (!android::base::Realpath(source, &real_source)) {
            real_source = source;
        }

        // Clear errno prior to calling `mount`, to avoid clobbering with any errno that
        // may have been set from prior calls (e.g. realpath).
        errno = 0;
        ret = mount(real_source.c_str(), target.c_str(), entry.fs_type.c_str(), mountflags,
                    opts.c_str());
        save_errno = errno;