From 453f4f4c66316d52c288cf0daec66134e52e9ee5 Mon Sep 17 00:00:00 2001 From: Om Date: Mon, 31 Aug 2026 03:37:39 +0530 Subject: [PATCH] Check errors that were discarded before use InitUAPI ignored the error from UAPIOpen and passed the resulting nil *os.File to UAPIListen, which hands it to net.FileListener. That panics rather than returning an error, because net/file.go reads f.Name() for the error message before checking the file. Starting a second instance on an interface ("unix socket in use") or starting without root (MkdirAll on the socket directory) both reach it, so the two likeliest startup mistakes print a nil-pointer stack trace instead of the message that was already written for them. Linux and darwin were identical here. Two smaller ones of the same shape: the pubkey MarshalText error in the key command was overwritten by the Fprintln error before it was tested, so a failure there printed an empty public key and exited 0, and BundleConfig dropped the yaml.Marshal error and went on to sign the result. --- cmd/utils.go | 3 +++ core/sys_darwin.go | 3 +++ core/sys_linux.go | 3 +++ state/distribution.go | 3 +++ 4 files changed, 12 insertions(+) diff --git a/cmd/utils.go b/cmd/utils.go index fd32851f..2412cae6 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -58,6 +58,9 @@ var keyCmd = &cobra.Command{ } fmt.Println(string(privKeyStr)) pubKeyStr, err := privKey.Pubkey().MarshalText() + if err != nil { + panic(err) + } _, err = fmt.Fprintln(os.Stderr, string(pubKeyStr)) if err != nil { panic(err) diff --git a/core/sys_darwin.go b/core/sys_darwin.go index e9580568..55ab99a8 100644 --- a/core/sys_darwin.go +++ b/core/sys_darwin.go @@ -11,6 +11,9 @@ import ( func InitUAPI(logger *slog.Logger, itfName string) (net.Listener, error) { fileUAPI, err := ipc.UAPIOpen(itfName) + if err != nil { + return nil, err + } uapi, err := ipc.UAPIListen(itfName, fileUAPI) if err != nil { diff --git a/core/sys_linux.go b/core/sys_linux.go index 0fe998a3..c38ec044 100644 --- a/core/sys_linux.go +++ b/core/sys_linux.go @@ -12,6 +12,9 @@ import ( func InitUAPI(logger *slog.Logger, itfName string) (net.Listener, error) { fileUAPI, err := ipc.UAPIOpen(itfName) + if err != nil { + return nil, err + } uapi, err := ipc.UAPIListen(itfName, fileUAPI) if err != nil { diff --git a/state/distribution.go b/state/distribution.go index 9b56d20f..bfcd0eb9 100644 --- a/state/distribution.go +++ b/state/distribution.go @@ -78,6 +78,9 @@ func BundleConfig(config string, rootKey NyPrivateKey) (string, error) { cfg.Timestamp = time.Now().UnixNano() plainText, err := yaml.Marshal(cfg) + if err != nil { + return "", err + } bundle, err := SignBundle(plainText, rootKey) if err != nil {