mirror of
https://github.com/filebrowser/filebrowser.git
synced 2026-01-23 02:35:10 +00:00
fix: correctly check if command is allowed when using shell
This commit is contained in:
parent
f84a6db680
commit
4d830f707f
4 changed files with 25 additions and 34 deletions
|
|
@ -1,33 +1,24 @@
|
|||
package runner
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
)
|
||||
|
||||
// ParseCommand parses the command taking in account if the current
|
||||
// instance uses a shell to run the commands or just calls the binary
|
||||
// directly.
|
||||
func ParseCommand(s *settings.Settings, raw string) ([]string, error) {
|
||||
var command []string
|
||||
|
||||
if len(s.Shell) == 0 || s.Shell[0] == "" {
|
||||
cmd, args, err := SplitCommandAndArgs(raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = exec.LookPath(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
command = append(command, cmd)
|
||||
command = append(command, args...)
|
||||
} else {
|
||||
command = append(s.Shell, raw) //nolint:gocritic
|
||||
func ParseCommand(s *settings.Settings, raw string) (command []string, name string, err error) {
|
||||
name, args, err := SplitCommandAndArgs(raw)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return command, nil
|
||||
if len(s.Shell) == 0 || s.Shell[0] == "" {
|
||||
command = append(command, name)
|
||||
command = append(command, args...)
|
||||
} else {
|
||||
command = append(s.Shell, raw)
|
||||
}
|
||||
|
||||
return command, name, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue