Description
New() currently validates that the parsed OCI spec contains a linux section, but does not validate that spec.Root is present.
A syntactically valid but structurally incomplete config.json, such as:
can therefore reach code paths that dereference spec.Root.Path, resulting in a nil pointer panic instead of returning a validation error.
I also found that when valid unikernel annotations are present, New() can return successfully while u.Spec.Root == nil, leaving an invalid Unikontainer that may panic later.
Relevant code
New() currently checks:
if spec == nil || spec.Linux == nil {
return nil, fmt.Errorf("invalid OCI spec: linux section is required")
}
but GetUnikernelConfig() later uses:
rootFSDir := spec.Root.Path
and other paths such as InitialSetup() and Exec() also access u.Spec.Root.Path.
Minimal reproducer
Create a bundle containing:
as config.json and call New() with that bundle.
Actual behavior
urunc can panic with a nil pointer dereference when the configuration fallback path accesses spec.Root.Path.
A spec containing valid unikernel annotations but no root section can also be accepted by New(), leaving Spec.Root == nil.
Expected behavior
Structurally incomplete OCI specs should be be rejected with a validation error, for example:
invalid OCI spec: root section is required
Possible direction
Validate that spec.Root is present before returning from New() / Get(), alongside the existing validation of spec.Linux.
A regression test using a minimal spec with linux present and root missing could cover this case.
Description
New()currently validates that the parsed OCI spec contains alinuxsection, but does not validate thatspec.Rootis present.A syntactically valid but structurally incomplete
config.json, such as:{ "linux": {} }can therefore reach code paths that dereference
spec.Root.Path, resulting in a nil pointer panic instead of returning a validation error.I also found that when valid unikernel annotations are present,
New()can return successfully whileu.Spec.Root == nil, leaving an invalidUnikontainerthat may panic later.Relevant code
New()currently checks:but
GetUnikernelConfig()later uses:and other paths such as
InitialSetup()andExec()also accessu.Spec.Root.Path.Minimal reproducer
Create a bundle containing:
{ "linux": {} }as
config.jsonand callNew()with that bundle.Actual behavior
urunc can panic with a nil pointer dereference when the configuration fallback path accesses
spec.Root.Path.A spec containing valid unikernel annotations but no
rootsection can also be accepted byNew(), leavingSpec.Root == nil.Expected behavior
Structurally incomplete OCI specs should be be rejected with a validation error, for example:
Possible direction
Validate that
spec.Rootis present before returning fromNew()/Get(), alongside the existing validation ofspec.Linux.A regression test using a minimal spec with
linuxpresent androotmissing could cover this case.