Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Feb 14, 2023
1 parent c8da038 commit 24ba2a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
30 changes: 16 additions & 14 deletions unix/pledge_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ func Pledge(promises, execpromises string) error {

// OS support for execpromises is required only when execpromises is not
// the empty string.
err = supportsExecpromises(maj, min, execpromises != "")
if err != nil {
return err
if execpromises != "" {
err = supportsExecpromises(maj, min)
if err != nil {
return err
}
}

_promises, err := BytePtrFromString(promises)
promisesBytes, err := BytePtrFromString(promises)
if err != nil {
return err
}

// This variable will hold either a nil pointer or a pointer to the
// NUL-terminated execpromises string.
var _execpromises *byte
var execpromisesBytes *byte

// If we're running on OpenBSD >= 6.3, pass execpromises to the syscall.
// While an empty execpromises string is required by this API on
Expand All @@ -54,10 +56,10 @@ func Pledge(promises, execpromises string) error {
if err != nil {
return err
}
_execpromises = exptr
execpromisesBytes = exptr
}

return pledge(_promises, _execpromises)
return pledge(promisesBytes, execpromisesBytes)
}

// PledgePromises implements the pledge syscall.
Expand All @@ -66,12 +68,12 @@ func Pledge(promises, execpromises string) error {
//
// For more information see pledge(2).
func PledgePromises(promises string) error {
_promises, err := BytePtrFromString(promises)
promisesBytes, err := BytePtrFromString(promises)
if err != nil {
return err
}

return pledge(_promises, nil)
return pledge(promisesBytes, nil)
}

// PledgeExecpromises implements the pledge syscall.
Expand All @@ -88,17 +90,17 @@ func PledgeExecpromises(execpromises string) error {
return err
}

err = supportsExecpromises(maj, min, true)
err = supportsExecpromises(maj, min)
if err != nil {
return err
}

_execpromises, err := BytePtrFromString(execpromises)
execpromisesBytes, err := BytePtrFromString(execpromises)
if err != nil {
return err
}

return pledge(nil, _execpromises)
return pledge(nil, execpromisesBytes)
}

// majmin returns major and minor version number for an OpenBSD system.
Expand Down Expand Up @@ -126,10 +128,10 @@ func majmin() (major int, minor int, err error) {

// supportsExecpromises checks for availability of the execpromises argument to
// the pledge(2) syscall based on the running OpenBSD version.
func supportsExecpromises(maj, min int, required bool) error {
func supportsExecpromises(maj, min int) error {
// If OpenBSD <= 6.2 and execpromises is not empty,
// return an error - execpromises is not available before 6.3
if (maj < 6 || (maj == 6 && min <= 2)) && required {
if maj < 6 || (maj == 6 && min <= 2) {
return fmt.Errorf("cannot use execpromises on OpenBSD %d.%d", maj, min)
}

Expand Down
6 changes: 3 additions & 3 deletions unix/unveil_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ package unix
// Note that the special case of blocking further
// unveil calls is handled by UnveilBlock.
func Unveil(path string, flags string) error {
_path, err := BytePtrFromString(path)
pathBytes, err := BytePtrFromString(path)
if err != nil {
return err
}
_flags, err := BytePtrFromString(flags)
flagsBytes, err := BytePtrFromString(flags)
if err != nil {
return err
}
return unveil(_path, _flags)
return unveil(pathBytes, flagsBytes)
}

// UnveilBlock blocks future unveil calls.
Expand Down

0 comments on commit 24ba2a1

Please sign in to comment.