diff --git a/docs/guides/native/kernel-build-config.md b/docs/guides/native/kernel-build-config.md index d7b4a48098..c270743547 100644 --- a/docs/guides/native/kernel-build-config.md +++ b/docs/guides/native/kernel-build-config.md @@ -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 diff --git a/src/domain/native/kernelBuildConfig.ts b/src/domain/native/kernelBuildConfig.ts index d2603965f9..ffa57e8d9d 100644 --- a/src/domain/native/kernelBuildConfig.ts +++ b/src/domain/native/kernelBuildConfig.ts @@ -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; diff --git a/tests/acceptance/kernelBuildConfigCli.test.ts b/tests/acceptance/kernelBuildConfigCli.test.ts index d4ec03ed85..1e59135d57 100644 --- a/tests/acceptance/kernelBuildConfigCli.test.ts +++ b/tests/acceptance/kernelBuildConfigCli.test.ts @@ -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: [], + }); + }, +);