Repository navigation
generate: report a JSON null inside an array of objects - #176
Merged
Merged
Conversation
make_*() returns NULL without setting *err when the value it was given
is absent, and callers rely on that to tell an absent optional field
from a parse failure:
ret->seccomp = make_..._seccomp (get_val (tree, "seccomp", ...), ctx, err);
if (ret->seccomp == NULL && *err != 0)
return NULL;
A null element of an array of objects reaches make_*() as a NULL tree
and therefore takes the very same path, so the failure was mistaken for
an absent field and swallowed. The enclosing object was silently
dropped instead of the document being rejected:
"seccomp": {"defaultAction": "SCMP_ACT_ERRNO", "syscalls": [null]}
parsed without any error at all and yielded a config with no seccomp at
all, which for a runtime means a container that ends up unconfined.
"hooks": {"prestart": [null]} likewise dropped the hooks, while
"mounts": [null] did fail, but with "(null)" as the error message.
Allocation failures inside make_*() had the same problem, as they too
returned NULL leaving *err untouched.
Make an absent value the only case where make_*() returns NULL without
setting *err, and report every other failure:
- array and map element checks set an error when the callee did not
- allocation failures report "error allocating memory"
Add tests/test-16.c covering a null element at several depths.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Collaborator
Author
|
@giuseppe PTAL |
giuseppe
approved these changes
Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make_*()returns NULL without setting*errwhen the value it was given is absent, and callers rely on that to tell an absent optional field from a parse failure:A null element of an array of objects reaches
make_*()as a NULL tree and therefore takes the very same path, so the failure was mistaken for an absent field and swallowed: the enclosing object was silently dropped instead of the document being rejected.Measured against crun, one null element in the document used to give:
seccomp.syscalls[].args: [null]seccompdroppedinvalid element in array 'args'seccomp.syscalls: [null]seccompdroppedinvalid element in array 'syscalls'hooks.prestart: [null]invalid element in array 'prestart'mounts: [null](null)invalid element in array 'mounts'linux.devices: [null]no `linux` block specifiedinvalid element in array 'devices'linux.namespaces: [null]no `linux` block specifiedinvalid element in array 'namespaces'linux.uidMappings: [null]no `linux` block specifiedinvalid element in array 'uidMappings'The first three are fail-open: for a runtime, a dropped
seccompblock means the container ends up unconfined, and a droppedprestarthook means setup that silently never runs. The other four did fail, but pointed at the wrong place -- thelinuxblock is present, one element inside it is not valid -- and one of them printed a NULL pointer as the error message.Allocation failures inside
make_*()had the same problem, as they too returned NULL leaving*erruntouched.This makes an absent value the only case where
make_*()returns NULL without setting*err, and reports every other failure:error allocating memorytests/test-16.ccovers a null element at several depths; without the change all seven cases fail.Verified:
make check16/16 here, and crun's full python test suite rebuilt against this shows no regressions.