Skip to content

validate: fix panic on missing host-specific hook - #825

Open
RaphaelFakhri wants to merge 1 commit into
opencontainers:masterfrom
RaphaelFakhri:validate-hook-stat-panic
Open

RaphaelFakhri wants to merge 1 commit into
opencontainers:masterfrom
RaphaelFakhri:validate-hook-stat-panic

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

With --host-specific, checkEventHooks reports a hook path that os.Stat cannot find, but then calls Mode() on the nil FileInfo anyway. As a result, oci-runtime-tool --host-specific validate panics on any bundle whose hook path is missing on the host, instead of printing the "cannot find hook" error.

This change checks the executable bit only when the stat succeeds.

Fixes #824

Testing

  • Adds TestCheckHooksHostSpecific, which covers an executable hook, a non-executable hook, and a missing hook. Without the fix, the missing-hook case panics at validate/validate.go:302.
  • End to end: a bundle created with --hooks-prestart-add '{"path":"/no/such/hook"}' now makes oci-runtime-tool --host-specific validate exit 1 with cannot find prestart hook: /no/such/hook. Before the fix, it panicked with exit code 2.
  • go test ./validate/... ./generate/... ./filepath/, go vet ./validate/, gofmt -s -l validate/, and golangci-lint run ./... (v2.15.0) all pass.

With --host-specific, checkEventHooks reports a hook path that cannot be
stat'ed, but then calls Mode() on the nil FileInfo anyway, so
`oci-runtime-tool --host-specific validate` panics instead of printing
the "cannot find hook" error. Only check the executable bit when the
stat succeeds.

Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner November 3, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

validate: --host-specific panics when a hook path does not exist

1 participant