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:
@@ -8,10 +8,12 @@ import {
|
||||
LC,
|
||||
buildVersionCommand,
|
||||
dylibCommand,
|
||||
dyldEnvironmentCommand,
|
||||
machoImage,
|
||||
rpathCommand,
|
||||
} from "../../../src/artifacts/apple/MachoImage.fixture.js";
|
||||
import { dylibResolutionResultSchema } from "../../../src/domain/apple/dylibResolution.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
@@ -254,3 +256,113 @@ describe.skipIf(process.getuid?.() === 0)(
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"reports embedded path overrides as conditional without changing diagnostic-only resolution",
|
||||
async ({ cli }) => {
|
||||
for (const [setting, expected] of [
|
||||
["DYLD_LIBRARY_PATH=/external", "conditional"],
|
||||
["DYLD_PRINT_LIBRARIES=1", "resolved"],
|
||||
["DYLD_FALLBACK_LIBRARY_PATH=/external", "resolved"],
|
||||
["DYLD_FRAMEWORK_PATH=/external", "resolved"],
|
||||
["DYLD_ROOT_PATH=/external", "resolved"],
|
||||
["DYLD_OVERLAY_PATH=/external", "resolved"],
|
||||
] as const) {
|
||||
const app = await fixtureApp();
|
||||
await writeFiles(app, {
|
||||
"Contents/MacOS/App": machoImage({
|
||||
commands: [
|
||||
dyldEnvironmentCommand(setting),
|
||||
buildVersionCommand(1),
|
||||
rpathCommand("@executable_path/../Absent"),
|
||||
rpathCommand("@executable_path/../Frameworks"),
|
||||
dylibCommand(LC.LOAD_DYLIB, "@rpath/libcore.dylib"),
|
||||
],
|
||||
}),
|
||||
});
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"trace-dylib-resolution",
|
||||
app,
|
||||
"--root",
|
||||
"Contents/MacOS/App",
|
||||
"--json",
|
||||
],
|
||||
environment: ENVIRONMENT,
|
||||
});
|
||||
expect(result.exitCode, JSON.stringify(result.json)).toBe(0);
|
||||
const trace = dylibResolutionResultSchema.parse(
|
||||
parseEvidence(result.json).normalized_result,
|
||||
);
|
||||
expect(trace.edges[0]?.resolution.status).toBe(expected);
|
||||
expect(trace.coverage.status).toBe(
|
||||
expected === "conditional" ? "partial" : "complete",
|
||||
);
|
||||
expect(
|
||||
trace.images.find(({ path }) => path === "Contents/MacOS/App")
|
||||
?.slices[0]?.dyld_environment,
|
||||
).toEqual([setting]);
|
||||
if (expected === "conditional")
|
||||
expect(trace.findings[0]?.explanation).toContain(
|
||||
"does not establish which image dyld will load",
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"retains definitive load findings for an explicitly selected app library root",
|
||||
async ({ cli }) => {
|
||||
const app = await fixtureApp();
|
||||
const settings = [
|
||||
"DYLD_LIBRARY_PATH=/external",
|
||||
"DYLD_INSERT_LIBRARIES=/external/injected.dylib",
|
||||
];
|
||||
await writeFiles(app, {
|
||||
"Contents/Frameworks/libcore.dylib": 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"),
|
||||
],
|
||||
}),
|
||||
"Contents/Frameworks/child.dylib": machoImage({
|
||||
fileType: FILE_TYPE.dylib,
|
||||
commands: [buildVersionCommand(1)],
|
||||
}),
|
||||
});
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"trace-dylib-resolution",
|
||||
app,
|
||||
"--root",
|
||||
"Contents/Frameworks/libcore.dylib",
|
||||
"--json",
|
||||
],
|
||||
environment: ENVIRONMENT,
|
||||
});
|
||||
expect(result.exitCode, JSON.stringify(result.json)).toBe(0);
|
||||
const trace = dylibResolutionResultSchema.parse(
|
||||
parseEvidence(result.json).normalized_result,
|
||||
);
|
||||
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 === "Contents/Frameworks/libcore.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