internal/pkg: exec nil path check during cure
All checks were successful
Test / Create distribution (push) Successful in 53s
Test / Sandbox (push) Successful in 2m49s
Test / ShareFS (push) Successful in 4m44s
Test / Hpkg (push) Successful in 5m10s
Test / Sandbox (race detector) (push) Successful in 5m17s
Test / Hakurei (race detector) (push) Successful in 7m32s
Test / Hakurei (push) Successful in 5m36s
Test / Flake checks (push) Successful in 1m55s

This results in os.ErrInvalid instead of a panic, which hopefully improves user experience.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-06 17:46:12 +09:00
parent f6d32e482a
commit e7e9b4caea
2 changed files with 31 additions and 6 deletions

View File

@@ -84,9 +84,17 @@ func (a *execArtifact) Kind() Kind { return KindExec }
func (a *execArtifact) Params() []byte {
var buf bytes.Buffer
for _, p := range a.paths {
buf.WriteString(p.P.String())
id := Ident(p.A)
buf.Write(id[:])
if p.P != nil {
buf.WriteString(p.P.String())
} else {
buf.WriteString("invalid P\x00")
}
if p.A != nil {
id := Ident(p.A)
buf.Write(id[:])
} else {
buf.WriteString("invalid A\x00")
}
}
buf.WriteByte(0)
buf.WriteString(a.dir.String())
@@ -106,9 +114,11 @@ func (a *execArtifact) Params() []byte {
// Dependencies returns a slice of all artifacts collected from caller-supplied
// [ExecContainerPath].
func (a *execArtifact) Dependencies() []Artifact {
artifacts := make([]Artifact, len(a.paths))
for i, p := range a.paths {
artifacts[i] = p.A
artifacts := make([]Artifact, 0, len(a.paths))
for _, p := range a.paths {
if p.A != nil {
artifacts = append(artifacts, p.A)
}
}
return artifacts
}
@@ -123,6 +133,9 @@ func (a *execArtifact) Cure(c *CureContext) (err error) {
paths := make([][2]*check.Absolute, len(a.paths))
for i, p := range a.paths {
if p.P == nil || p.A == nil {
return os.ErrInvalid
}
paths[i][1] = p.P
}

View File

@@ -96,6 +96,18 @@ func TestExec(t *testing.T) {
},
}),
), nil, pkg.Checksum{}, errors.Join(stub.UniqueError(0xcafe))},
{"invalid paths", pkg.NewExec(
t.Context(),
msg,
0,
check.MustAbs("/work"),
[]string{"HAKUREI_TEST=1"},
check.MustAbs("/opt/bin/testtool"),
[]string{"testtool"},
pkg.ExecContainerPath{},
), nil, pkg.Checksum{}, os.ErrInvalid},
})
// check init failure passthrough