From 73554211bc57b6227c2ce279b949cb518aaa212e Mon Sep 17 00:00:00 2001 From: Entrpi Date: Wed, 4 Nov 2026 05:57:27 +1100 Subject: [PATCH] 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. --- docs/reverse-engineering-tools.md | 5 +++-- .../reverse/ReverseEngineeringService.ts | 13 ++++++++++-- src/process/ExecutableLookup.ts | 20 +++++++++++++++---- .../reverseEngineeringToolIdentity.test.ts | 14 ++++++++----- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/docs/reverse-engineering-tools.md b/docs/reverse-engineering-tools.md index ea3279239d..1af3a6c131 100644 --- a/docs/reverse-engineering-tools.md +++ b/docs/reverse-engineering-tools.md @@ -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 diff --git a/src/application/reverse/ReverseEngineeringService.ts b/src/application/reverse/ReverseEngineeringService.ts index 8f4f1fca99..5a1a15fc32 100644 --- a/src/application/reverse/ReverseEngineeringService.ts +++ b/src/application/reverse/ReverseEngineeringService.ts @@ -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); diff --git a/src/process/ExecutableLookup.ts b/src/process/ExecutableLookup.ts index b14f58ba62..e90db860d8 100644 --- a/src/process/ExecutableLookup.ts +++ b/src/process/ExecutableLookup.ts @@ -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(); } diff --git a/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts b/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts index 811d6127d8..69464712a7 100644 --- a/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts +++ b/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts @@ -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", });