Skip to content

Commit

Permalink
actions/run: Check script exists during recipe verification
Browse files Browse the repository at this point in the history
If a script doesn't exist or the permissions are wrong, the
recipe exits during execution. Let's check early if the
script exists on the host filesystem and that the file has
executable permission bit set.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
  • Loading branch information
obbardc committed Jan 7, 2022
1 parent a95ed84 commit f4d49c5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions actions/run_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ package actions
import (
"errors"
"github.com/go-debos/fakemachine"
"fmt"
"os"
"path"
"strings"

Expand All @@ -68,6 +70,22 @@ func (run *RunAction) Verify(context *debos.DebosContext) error {
if run.Script == "" && run.Command == "" {
return errors.New("Script and Command both cannot be empty")
}

if run.Script != "" {
argv := strings.SplitN(run.Script, " ", 2)
script := debos.CleanPathAt(argv[0], context.RecipeDir)

stat, err := os.Stat(script)
if err != nil {
return err
}

/* check the script is executable */
if stat.IsDir() || stat.Mode()&0111 == 0 {
return fmt.Errorf("Script %s is not executable", script)
}
}

return nil
}

Expand Down

0 comments on commit f4d49c5

Please sign in to comment.