diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-01-01 21:34:57 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-01-01 21:34:57 +0900 |
| commit | 6acd0d4e88af6a80836c5409023bbb6ebc57231f (patch) | |
| tree | c0b5ab89cb7549e817c5dac9c0894279ac376275 /internal/linux | |
| parent | 35b714231768d11b82e575701ca5c7a081e2c542 (diff) | |
linux/std: handle fsu exit status 1
Printing "exit status 1" is confusing. This handles the ExitError and returns EACCES instead.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/linux')
| -rw-r--r-- | internal/linux/std.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/internal/linux/std.go b/internal/linux/std.go index 219997ee..a82fff26 100644 --- a/internal/linux/std.go +++ b/internal/linux/std.go @@ -1,6 +1,7 @@ package linux import ( + "errors" "io" "io/fs" "os" @@ -8,6 +9,7 @@ import ( "os/user" "strconv" "sync" + "syscall" "git.gensokyo.uk/security/fortify/internal" "git.gensokyo.uk/security/fortify/internal/fmsg" @@ -79,9 +81,15 @@ func (s *Std) Uid(aid int) (int, error) { cmd.Stderr = os.Stderr // pass through fatal messages cmd.Env = []string{"FORTIFY_APP_ID=" + strconv.Itoa(aid)} cmd.Dir = "/" - var p []byte + var ( + p []byte + exitError *exec.ExitError + ) + if p, u.err = cmd.Output(); u.err == nil { u.uid, u.err = strconv.Atoi(string(p)) + } else if errors.As(u.err, &exitError) && exitError != nil && exitError.ExitCode() == 1 { + u.err = syscall.EACCES } return u.uid, u.err } |
