From db71fbe22bea41e92b9a037a2b608a3350097f5f Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 17 Feb 2025 12:17:01 +0900 Subject: [PATCH] system/tmpfiles: fail gracefully in API misuse Panicking here leaves garbage behind. Not ideal if this package is going to be exported. Signed-off-by: Ophestra --- internal/system/tmpfiles.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/system/tmpfiles.go b/internal/system/tmpfiles.go index 5a2307f..5130f2e 100644 --- a/internal/system/tmpfiles.go +++ b/internal/system/tmpfiles.go @@ -2,6 +2,7 @@ package system import ( "bytes" + "errors" "fmt" "io" "os" @@ -35,6 +36,11 @@ func (t *Tmpfile) Type() Enablement { return Process } func (t *Tmpfile) apply(_ *I) error { fmsg.Verbose("copying", t) + if t.payload == nil { + // this is a misuse of the API; do not return an error message + return errors.New("invalid payload") + } + if b, err := os.Stat(t.src); err != nil { return fmsg.WrapErrorSuffix(err, fmt.Sprintf("cannot stat %q:", t.src))