fix(providers): validate ELF versions and preserve probe cancellation
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { expect, it } from "vitest";
|
||||
import {
|
||||
recordedCrashFixture,
|
||||
recordedCrashFixtureBytes,
|
||||
} from "../../fixtures/binaryDiagnostics/recordedCrash.js";
|
||||
import { validateRecordedCrashStructure } from "../../../src/native/pwntools/RecordedCrashStructureBindings.js";
|
||||
|
||||
it.each([
|
||||
[6, 0],
|
||||
[6, 2],
|
||||
[20, 0],
|
||||
[20, 2],
|
||||
] as const)(
|
||||
"rejects non-current ELF version at byte %i: %i",
|
||||
(offset, version) => {
|
||||
const report = recordedCrashFixture();
|
||||
const snapshot = recordedCrashFixtureBytes(report);
|
||||
if (offset === 6) snapshot[offset] = version;
|
||||
else snapshot.writeUInt32LE(version, offset);
|
||||
expect(() =>
|
||||
validateRecordedCrashStructure(
|
||||
report,
|
||||
snapshot,
|
||||
report.decoder_diagnostics,
|
||||
),
|
||||
).toThrow(/Reported core structure differs/);
|
||||
},
|
||||
);
|
||||
@@ -43,6 +43,10 @@ it
|
||||
"omitted-physical-note",
|
||||
"hidden-segment",
|
||||
"wrong-header-range",
|
||||
"wrong-ei-version-zero",
|
||||
"wrong-ei-version-two",
|
||||
"wrong-e-version-zero",
|
||||
"wrong-e-version-two",
|
||||
"wrong-note-kind",
|
||||
"wrong-owner-display",
|
||||
"wrong-pid",
|
||||
@@ -60,6 +64,11 @@ it
|
||||
true,
|
||||
scenario === "wrong-owner-display",
|
||||
);
|
||||
if (scenario.startsWith("wrong-ei-version-"))
|
||||
bytes[6] = Number(scenario.at(-1));
|
||||
if (scenario.startsWith("wrong-e-version-"))
|
||||
bytes.writeUInt32LE(Number(scenario.at(-1)), 20);
|
||||
if (scenario.startsWith("wrong-e")) await writeFile(path, bytes);
|
||||
let owned = "";
|
||||
const provider = new PwntoolsRecordedCrashProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { access } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it, onTestFinished } from "vitest";
|
||||
import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js";
|
||||
import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../../../tests/support/workspace/workspaceFixture.js";
|
||||
import { inspectPwndbgCore } from "../../../src/native/pwndbg/PwndbgCoreContext.js";
|
||||
|
||||
const diagnostics = { stdout: "", stderr: "", truncated: false };
|
||||
|
||||
it.each(["pre-aborted", "aborted-during-probe"] as const)(
|
||||
"cancellation wins over debugger path failures: %s",
|
||||
async (scenario) => {
|
||||
const workspace = await createTestWorkspace("rea-pwndbg-cancel-");
|
||||
onTestFinished(() => removeTestWorkspace(workspace.root));
|
||||
const controller = new AbortController();
|
||||
const gdb = join(workspace.root, "missing-gdb");
|
||||
let probes = 0;
|
||||
const probePath = async () => {
|
||||
probes++;
|
||||
if (scenario === "aborted-during-probe") {
|
||||
await new Promise<void>((resolve) => {
|
||||
setImmediate(() => {
|
||||
controller.abort();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
throw new Error("path became unavailable");
|
||||
}
|
||||
throw new Error("path is unavailable");
|
||||
};
|
||||
if (scenario === "pre-aborted") controller.abort();
|
||||
await expect(
|
||||
inspectPwndbgCore({
|
||||
environment: {
|
||||
REA_PWNDBG_GDB: gdb,
|
||||
REA_PWNDBG_GDBINIT: join(workspace.root, "missing-init"),
|
||||
REA_PWNDBG_VENV_PATH: join(workspace.root, "missing-venv"),
|
||||
},
|
||||
rootPath: workspace.root,
|
||||
diagnostics,
|
||||
options: { signal: controller.signal },
|
||||
probePath,
|
||||
}),
|
||||
).rejects.toBeInstanceOf(AnalysisCancelledError);
|
||||
expect(probes).toBe(scenario === "pre-aborted" ? 0 : 1);
|
||||
await expect(
|
||||
access(join(workspace.root, "debugger")),
|
||||
).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -139,6 +139,7 @@ export const recordedCrashSignalFixture = (path?: string): RecordedCrash => {
|
||||
export const recordedCrashFixtureBytes = (value: RecordedCrash): Buffer => {
|
||||
const bytes = Buffer.alloc(value.artifact.bytes);
|
||||
bytes.set([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1]);
|
||||
bytes.writeUInt32LE(1, 20);
|
||||
bytes.writeUInt16LE(4, 16);
|
||||
bytes.writeUInt16LE(62, 18);
|
||||
bytes.writeBigUInt64LE(64n, 32);
|
||||
|
||||
Reference in New Issue
Block a user