Repository navigation
Description
A primitive JSON null variable in host_specific.json crashes cf-promises and cf-agent during context loading.
Plain-language logic review — awaiting human verification
A generated settings file can contain null, JSON's way of saying "no value". For a simple CFEngine variable, the loader expects an actual value. Previously it passed that missing value onward as though it were usable text; in our debug runs, a safety check stopped the entire process. One bad setting therefore prevented the program from continuing normally.
For example, {"vars":{"bad":null,"good":"still here"}} contains one unusable setting and one usable setting. The change checks for the unusable one before converting it: report an error naming bad, do not install that value, then continue loading good. It does not turn null into the text "null", an empty string, or a request to delete a previously defined variable.
This check only handles a null that is itself the whole simple value. Existing handling of lists and structured data stays intact:
| Input value | What the fix does |
|---|---|
null as a simple variable |
Report the invalid value and continue with other entries |
["a", null, "b"] |
Keep existing behavior: skip the null list item |
[null] |
Keep existing empty-list behavior |
{"inside": null} as structured data |
Keep the nested null as data |
The proof is a before/after comparison using the same input and tests. Without the fix, all eight scalar-null probes (four forms in two programs) aborted. With it, all eight exited successfully, reported the invalid setting and loaded the good neighbor. The six list/data/projector control probes exited successfully both ways. The new regression test also fails when only the C fix is removed. These were Linux debug builds; this is not a claim about every production build or a claim that tendcf/nix2cf currently emits one of the bad values.
The human decision to verify: should an invalid simple null produce an error and leave the rest of the settings usable, while nulls inside existing list/data formats retain their current meaning? The diagnostics do not make the overall command exit nonzero in the tested cases. This fix prevents the crash; it does not make every invalid input a fatal validation error.
Human verification is pending. Independent AI reviews and passing tests do not substitute for it. No upstream submission is authorized by this section.
Reproducer
Place either document in an isolated workdir's data/host_specific.json, then run cf-promises --show-vars -f promises.cf against a minimal policy:
{"vars":{"k":null}}{"variables":{"k":{"value":null}}}The bare variables form and a namespace-qualified variable key reach the same scalar conversion.
Fix and compatibility
Reject only null scalar variable values with a diagnostic naming the key; continue loading valid neighboring entries. JsonPrimitiveToString() returns NULL for JSON null, so the value must not reach string logging or variable insertion. Preserve the existing tag-set cleanup on failure.
Nulls inside primitive lists are still skipped by the existing conversion; nested nulls inside data containers remain data. This fix does not modify def.json, JSON encoding, or simulate output.
Correction to the original issue: the old proposal rejected null-containing lists and described that as part of this fix. The current change deliberately preserves list behavior. Earlier text claiming a failsafe fallback is not evidence that a crashing process itself reached failsafe; the demonstrated failure is a crash during context loading.
Implementation and evidence
Previous implementation: #63 (preserved).
Refreshed PR: #91
Refreshed branch: https://github.com/djbclark/core/tree/fix/cmdb-null-value-crash-r4
Current head ca1d1c69e2b4240e0d1cc3dba9a44f8072ecb85f, based on upstream 270e6c36f4d0dcf73ded78d28ae9d7cfd9013564.
Fresh Ubuntu 24.04 aarch64 Linux gate, debug build, root, network disabled:
-
Unit suite: 79/79 test programs passed.
-
CMDB acceptance directory: 12 passed, 0 failed, 0 skipped. New regression checks scalar rejection, valid neighbors, null-containing lists, and a nested null.
-
Negative control: rebuilt with only
libpromises/cmdb.creverted to the upstream base270e6c36f4d0dcf73ded78d28ae9d7cfd9013564, keeping the new test. The new test failed (0 passed, 1 failed). -
Direct probes, each in both binaries: four null forms abort with SIGABRT (-6) without the fix and exit 0 with the fix, logging the rejection and loading a valid neighbor. Mixed/all-null lists, a nested-null object, and the tendcf projector fixture exit 0 on both versions. 28 before/after case/binary runs total. This is fresh debug-build evidence, not a release-build reproduction.
The first hosted run identified JSON fixture formatting; CFEngine's formatter corrected it without changing parsed values. The complete Linux gate and probes were rerun on the current head above. Hosted formatting, policy lint, shellcheck and unit tests pass; remaining CI jobs are in progress. Independent Opus 5.5 high and GPT-6 Astra high source/evidence reviews report no blocking code/security findings; both have confirmed the final-head delta and fresh evidence. Historical results in PR 63 apply to its old head, not this one.
The C patch also applies cleanly to active upstream refactor cfengine#6484 at b68070a2105ca33f04844f74ec3a2e23a912dc6b. That is an apply-check, not runtime verification of the refactor.
History
Originally tracked as CFE-4738 and cfengine#6316, closed in the August 2026 contribution-volume reset. This is a focused refresh; no new upstream submission has been made. The separate augments issue is #22.
Activity