fix(apple): validate dylib candidates and preserve search uncertainty (#1100)
* fix(apple): validate dylib candidates and preserve search uncertainty * fix(apple): scope embedded dyld uncertainty by search phase * fix(apple): scope dyld prefixes to eligible paths and platforms * fix(apple): ignore embedded process settings on library roots
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
LC,
|
||||
buildVersionCommand,
|
||||
dylibCommand,
|
||||
dyldEnvironmentCommand,
|
||||
machoImage,
|
||||
rpathCommand,
|
||||
} from "../../../src/artifacts/apple/MachoImage.fixture.js";
|
||||
@@ -204,3 +205,121 @@ it.skipIf(process.getuid?.() === 0)(
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"DYLD_LIBRARY_PATH=/external",
|
||||
"DYLD_PRINT_RPATHS=1",
|
||||
"DYLD_FALLBACK_LIBRARY_PATH=/external",
|
||||
"DYLD_FRAMEWORK_PATH=/external",
|
||||
"DYLD_ROOT_PATH=/external",
|
||||
"DYLD_OVERLAY_PATH=/external",
|
||||
])("preserves %s and its resolution semantics through MCP", async (setting) => {
|
||||
const root = await createTestTempDirectory("rea-dylib-environment-mcp-");
|
||||
const program = join(root, "program");
|
||||
await writeFile(
|
||||
program,
|
||||
machoImage({
|
||||
commands: [
|
||||
dyldEnvironmentCommand(setting),
|
||||
buildVersionCommand(1),
|
||||
dylibCommand(LC.LOAD_DYLIB, "@loader_path/child.dylib"),
|
||||
],
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "child.dylib"),
|
||||
machoImage({
|
||||
fileType: FILE_TYPE.dylib,
|
||||
commands: [buildVersionCommand(1)],
|
||||
}),
|
||||
);
|
||||
await withClient(async (client) => {
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: program },
|
||||
});
|
||||
expect(opened.isError).not.toBe(true);
|
||||
const result = await client.callTool({
|
||||
name: "trace_dylib_resolution",
|
||||
arguments: {},
|
||||
});
|
||||
expect(result.isError, JSON.stringify(result.structuredContent)).not.toBe(
|
||||
true,
|
||||
);
|
||||
const trace = dylibResolutionResultSchema.parse(
|
||||
structuredResult(result.structuredContent),
|
||||
);
|
||||
const overrides = setting.startsWith("DYLD_LIBRARY_PATH=");
|
||||
expect(trace.edges[0]?.resolution.status).toBe(
|
||||
overrides ? "conditional" : "resolved",
|
||||
);
|
||||
expect(trace.coverage.status).toBe(overrides ? "partial" : "complete");
|
||||
expect(
|
||||
trace.images.find(({ path }) => path === "program")?.slices[0]
|
||||
?.dyld_environment,
|
||||
).toEqual([setting]);
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores process settings on an explicitly selected library root through MCP", async () => {
|
||||
const root = await createTestTempDirectory("rea-dylib-root-mcp-");
|
||||
const path = join(root, "library.dylib");
|
||||
const settings = [
|
||||
"DYLD_LIBRARY_PATH=/external",
|
||||
"DYLD_INSERT_LIBRARIES=/external/injected.dylib",
|
||||
];
|
||||
await writeFile(
|
||||
path,
|
||||
machoImage({
|
||||
fileType: FILE_TYPE.dylib,
|
||||
commands: [
|
||||
buildVersionCommand(1),
|
||||
...settings.map(dyldEnvironmentCommand),
|
||||
dylibCommand(LC.LOAD_DYLIB, "@loader_path/child.dylib"),
|
||||
dylibCommand(LC.LOAD_DYLIB, "@loader_path/missing.dylib"),
|
||||
],
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "child.dylib"),
|
||||
machoImage({
|
||||
fileType: FILE_TYPE.dylib,
|
||||
commands: [buildVersionCommand(1)],
|
||||
}),
|
||||
);
|
||||
await withClient(async (client) => {
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path },
|
||||
});
|
||||
expect(opened.isError, JSON.stringify(opened.structuredContent)).not.toBe(
|
||||
true,
|
||||
);
|
||||
const result = await client.callTool({
|
||||
name: "trace_dylib_resolution",
|
||||
arguments: { roots: ["library.dylib"] },
|
||||
});
|
||||
expect(result.isError, JSON.stringify(result.structuredContent)).not.toBe(
|
||||
true,
|
||||
);
|
||||
const trace = dylibResolutionResultSchema.parse(
|
||||
structuredResult(result.structuredContent),
|
||||
);
|
||||
expect(trace.edges.map(({ resolution }) => resolution.status)).toEqual([
|
||||
"resolved",
|
||||
"unresolved",
|
||||
]);
|
||||
expect(trace.coverage.status).toBe("complete");
|
||||
expect(trace.findings.map(({ kind }) => kind)).toContain(
|
||||
"required-load-unresolved",
|
||||
);
|
||||
expect(
|
||||
trace.images.find(({ path }) => path === "library.dylib")?.slices[0]
|
||||
?.dyld_environment,
|
||||
).toEqual(settings);
|
||||
expect(
|
||||
trace.findings.find(({ kind }) => kind === "dyld-environment-present")
|
||||
?.explanation,
|
||||
).toContain("entries in this non-executable root are observations");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user