fix tests
This commit is contained in:
parent
95a457e823
commit
04bef4978c
|
|
@ -7,6 +7,8 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
|
|
@ -41,7 +43,14 @@ func ExecHelper(args []string) error {
|
|||
if err := syscall.Chdir(p.CWD); err != nil {
|
||||
return err
|
||||
}
|
||||
return syscall.Exec(p.Command[0], p.Command, envList(p.Env))
|
||||
// syscall.Exec requires an absolute path; resolve via PATH if needed
|
||||
cmd0 := p.Command[0]
|
||||
if !strings.HasPrefix(cmd0, "/") {
|
||||
if resolved, err := exec.LookPath(cmd0); err == nil {
|
||||
cmd0 = resolved
|
||||
}
|
||||
}
|
||||
return syscall.Exec(cmd0, p.Command, envList(p.Env))
|
||||
}
|
||||
|
||||
func envList(env map[string]string) []string {
|
||||
|
|
@ -76,10 +85,10 @@ func restrict(cfg *Config, cwd string, env map[string]string) error {
|
|||
Allowed uint64
|
||||
ParentFD int
|
||||
}{access, int(f)}
|
||||
_, _, e = unix.Syscall6(unix.SYS_LANDLOCK_ADD_RULE, fd, uintptr(1), uintptr(unsafe.Pointer(&rule)), 0, 0, 0)
|
||||
_, _, errno := unix.Syscall6(unix.SYS_LANDLOCK_ADD_RULE, fd, uintptr(1), uintptr(unsafe.Pointer(&rule)), 0, 0, 0)
|
||||
unix.Close(f)
|
||||
if e != nil {
|
||||
return fmt.Errorf("add landlock path %s: %w", p, e)
|
||||
if errno != 0 {
|
||||
return fmt.Errorf("add landlock path %s: %w", p, errno)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue