fix(elf): preserve unprefixed Kconfig hex values (#12516)

This commit is contained in:
morluto authored and GitHub committed 2026-11-19 20:53:49 +00:00
1 parent cd3590c8ee
commit 3dfd7c2f0d
3 files changed
+58 -4

No files matched your search

+5 -2
View File
@@ -72,11 +72,14 @@ Each entry has a `name`, a `kind`, and a `value`:
| `kind` | Source line | `value` |
| --------- | -------------------------- | ------------------------- |
| `y`, `m` | `CONFIG_X=y`, `CONFIG_X=m` | `y` or `m` |
| `number` | decimal or `0x` hex | the text as written |
| `number` | Kconfig integer or hex | the text as written |
| `string` | `CONFIG_X="..."` | decoded text (`\"`, `\\`) |
| `not_set` | `# CONFIG_X is not set` | `null` |
Banner text and configuration values are target-derived and untrusted.
Kconfig can write hexadecimal values without a `0x` prefix. REA preserves
the spelling and leaves the numeric base unresolved when the value alone
cannot establish it. Banner text and configuration values are target-derived
and untrusted.
## bzImage payloads
+5 -2
View File
@@ -59,9 +59,12 @@ const range = z.strictObject({
bytes: uint,
});
/** Matches a Kconfig `int` or `hex` value as written to `.config`. */
/**
* Kconfig writes `int` and `hex` lexemes as stored. Hex may omit its prefix,
* so a digit-only value does not establish a base without the symbol type.
*/
export const KERNEL_BUILD_CONFIG_NUMBER =
/^(?:-?(?:0|[1-9][0-9]*)|0[xX][0-9A-Fa-f]+)$/u;
/^(?:-(?:0|[1-9][0-9]*)|(?:0[xX])?[0-9A-Fa-f]+)$/u;
/** Length of the `IKCFG_ST` and `IKCFG_ED` markers. */
export const KERNEL_BUILD_CONFIG_MARKER_BYTES = 8;
@@ -8,6 +8,7 @@ import { toolContract } from "../../src/contracts/toolContracts.js";
import {
bzImageGzipFixture,
bzImageXzFixture,
embeddedKernelConfig,
kernelBuildConfigFixture,
} from "../../src/native/elf/KernelBuildConfig.fixture.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
@@ -152,3 +153,50 @@ cliTest(
});
},
);
cliTest(
"preserves the spelling of Kconfig hex values without a 0x prefix",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-kconfig-hex-cli-");
const path = join(root, "vmlinux");
const prefix = kernelBuildConfigFixture().subarray(0, 64);
const entries = [
{ name: "CONFIG_BARE_HEX", kind: "number", value: "AbCd" },
{ name: "CONFIG_PADDED_HEX", kind: "number", value: "00042" },
{ name: "CONFIG_PREFIXED_HEX", kind: "number", value: "0xABcd" },
{ name: "CONFIG_NEGATIVE_INT", kind: "number", value: "-42" },
];
const text = entries
.map(({ name, value }) => `${name}=${value}\n`)
.join("");
await writeFile(path, Buffer.concat([prefix, embeddedKernelConfig(text)]));
const result = await cli.run({
arguments: ["inspect-kernel-build-config", path, "--json"],
});
expect(result.exitCode, result.stderr).toBe(0);
expect(
contract.outputSchema.parse(result.json).normalized_result.config,
).toMatchObject({
status: "present",
option_count: entries.length,
entries,
});
await writeFile(
path,
Buffer.concat([prefix, embeddedKernelConfig("CONFIG_NOT_HEX=xyz\n")]),
);
const invalid = await cli.run({
arguments: ["inspect-kernel-build-config", path, "--json"],
});
expect(invalid.exitCode, invalid.stderr).toBe(0);
expect(
contract.outputSchema.parse(invalid.json).normalized_result.config,
).toMatchObject({
status: "malformed",
reason: "config_text_invalid",
entries: [],
});
},
);