mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 01:46:39 +00:00
fix(rizin): keep an explicitly selected path the lookup does not accept
An explicitly selected command that resolved to a file without execute permission ended the lookup as missing, with its absolute path only in the checked strings. The command then ran by its relative name, and the launch failure lost provider_executable_path. A missing lookup now reports the path an explicit selection names, and the service runs that path and keeps it, as it does for a path the host refuses to inspect. Process capture ignores the field and still rejects such a file as an invalid selection.
This commit is contained in:
1 parent
9c3bfe4a08
commit
73554211bc
4 files changed
+39
-13
No files matched your search
@@ -156,8 +156,9 @@ decides what runs. A found file that does not start with `ENOENT` or `EACCES`,
|
||||
as when a script's interpreter is missing or not executable, is one a native
|
||||
search moves past. The command then also runs as selected, with the version
|
||||
unknown, and a limitation names that file. When the host refuses to inspect an
|
||||
explicitly selected path (`EACCES` or `EPERM`), the command runs that path with
|
||||
the version unknown, and Evidence or the launch failure keeps it as
|
||||
explicitly selected path (`EACCES` or `EPERM`), or the lookup does not accept
|
||||
it, for example because it lacks execute permission, the command runs that
|
||||
path with the version unknown, and Evidence or the launch failure keeps it as
|
||||
`provider_executable_path`. A lookup or hash that stops waiting for a stalled
|
||||
`stat` or `access` leaves that call running; a later lookup or hash of the same
|
||||
path waits for it instead of starting another. A hash also ends at the deadline
|
||||
|
||||
@@ -956,15 +956,24 @@ export class ReverseEngineeringService {
|
||||
{ provider_executable_path: lookup.path },
|
||||
),
|
||||
);
|
||||
// The command launch reports an executable that cannot be selected.
|
||||
if (lookup.status !== "found")
|
||||
// The command launch reports an executable that cannot be selected. An
|
||||
// explicitly selected path runs as the lookup resolved it, so a launch
|
||||
// failure keeps where it looked.
|
||||
if (lookup.status !== "found") {
|
||||
const selected =
|
||||
lookup.status === "missing" ? lookup.selectedPath : undefined;
|
||||
return ok(
|
||||
unidentified(
|
||||
lookup.status === "no-working-directory"
|
||||
? "the executable could not be located: its lookup needed the working directory, which could not be read"
|
||||
: "the executable could not be located",
|
||||
selected,
|
||||
selected === undefined
|
||||
? undefined
|
||||
: { provider_executable_path: selected },
|
||||
),
|
||||
);
|
||||
}
|
||||
let sha256: string;
|
||||
try {
|
||||
sha256 = await this.#digest(lookup.path, signal, this.#stat, timeoutMs);
|
||||
|
||||
@@ -19,7 +19,12 @@ export type ExecutableLookup =
|
||||
readonly code: "EACCES" | "EPERM";
|
||||
readonly cause: unknown;
|
||||
}
|
||||
| { readonly status: "missing"; readonly checked: readonly string[] }
|
||||
| {
|
||||
readonly status: "missing";
|
||||
readonly checked: readonly string[];
|
||||
/** The path an explicitly selected command names, which its launch runs. */
|
||||
readonly selectedPath?: string;
|
||||
}
|
||||
/** A relative command, or a match under a relative PATH entry, needed the working directory, which could not be read. */
|
||||
| { readonly status: "no-working-directory"; readonly cause: unknown }
|
||||
/** The caller's signal or deadline ended the lookup before it finished. */
|
||||
@@ -88,6 +93,12 @@ export const lookupExecutable = async (
|
||||
const interruption = lookupInterruption(signal, timeoutMs);
|
||||
try {
|
||||
const checked: string[] = [];
|
||||
let selectedPath: string | undefined;
|
||||
const missing = (): ExecutableLookup => ({
|
||||
status: "missing",
|
||||
checked,
|
||||
...(selectedPath === undefined ? {} : { selectedPath }),
|
||||
});
|
||||
for (const entry of entries) {
|
||||
const entryBytes = Buffer.byteLength(entry);
|
||||
if (!explicit && PATH_MAX !== undefined && entryBytes >= PATH_MAX) {
|
||||
@@ -110,6 +121,7 @@ export const lookupExecutable = async (
|
||||
candidate = appendCallerPath(entry === "" ? "." : entry, command);
|
||||
unnamed = { cause };
|
||||
}
|
||||
if (explicit) selectedPath = candidate;
|
||||
const metadata = await interruption.race(
|
||||
shareFileCall(stat, candidate, () => stat(candidate)),
|
||||
);
|
||||
@@ -125,7 +137,7 @@ export const lookupExecutable = async (
|
||||
};
|
||||
checked.push(`${candidate}${systemErrorSuffix(code)}`);
|
||||
if (searchMovesPast(code)) continue;
|
||||
return { status: "missing", checked };
|
||||
return missing();
|
||||
}
|
||||
if (!metadata.value.isFile()) {
|
||||
checked.push(`${candidate} (not a regular file)`);
|
||||
@@ -146,9 +158,9 @@ export const lookupExecutable = async (
|
||||
: { status: "no-working-directory", cause: unnamed.cause };
|
||||
const code = systemErrorCode(executable.cause);
|
||||
checked.push(`${candidate}${systemErrorSuffix(code)}`);
|
||||
if (!searchMovesPast(code)) return { status: "missing", checked };
|
||||
if (!searchMovesPast(code)) return missing();
|
||||
}
|
||||
return { status: "missing", checked };
|
||||
return missing();
|
||||
} finally {
|
||||
interruption.release();
|
||||
}
|
||||
|
||||
@@ -711,10 +711,14 @@ posix.each([
|
||||
},
|
||||
);
|
||||
|
||||
posix(
|
||||
"keeps the resolved path of a relative selection the host refuses to inspect when its launch fails",
|
||||
async () => {
|
||||
posix.each([
|
||||
["the host refuses to inspect", "stat"],
|
||||
["lacks execute permission", "mode"],
|
||||
] as const)(
|
||||
"keeps the resolved path of a relative selection that %s when its launch fails",
|
||||
async (_description, refusal) => {
|
||||
const { executable, path } = await rizinExecutableFixture();
|
||||
if (refusal === "mode") await chmod(executable, 0o644);
|
||||
const run = vi.fn(
|
||||
async (
|
||||
_command: string,
|
||||
@@ -727,12 +731,12 @@ posix(
|
||||
const service = new TestReverseEngineeringService({
|
||||
run,
|
||||
// The relative selection resolves in the fixture's directory, where
|
||||
// the host refuses to inspect it.
|
||||
// the host refuses to inspect it or it lacks execute permission.
|
||||
lookup: (command, _directory, searchPath, bounds) =>
|
||||
lookupExecutable(command, () => dirname(executable), searchPath, {
|
||||
...bounds,
|
||||
stat: async (target) => {
|
||||
if (target === executable)
|
||||
if (refusal === "stat" && target === executable)
|
||||
throw Object.assign(new Error("permission denied"), {
|
||||
code: "EACCES",
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user