Skip to content

Commit

Permalink
Merge pull request #1659 from 89luca89/fix/prevalidate_checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored Nov 19, 2024
2 parents 90eb75c + bdc79c9 commit 5decd5c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pkg/build/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os/signal"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -142,6 +143,22 @@ func validateWith(data map[string]string, inputs map[string]config.Input) (map[s
if data[k] == "" {
data[k] = v.Default
}
if k == "expected-sha256" && data[k] != "" {
if !matchValidShaChars(data[k]) {
return data, fmt.Errorf("checksum input %q for pipeline contains invalid characters", k)
}
if len(data[k]) != 64 {
return data, fmt.Errorf("checksum input %q for pipeline, invalid length", k)
}
}
if k == "expected-sha512" && data[k] != "" {
if !matchValidShaChars(data[k]) {
return data, fmt.Errorf("checksum input %q for pipeline contains invalid characters", k)
}
if len(data[k]) != 128 {
return data, fmt.Errorf("checksum input %q for pipeline, invalid length", k)
}
}

if v.Required && data[k] == "" {
return data, fmt.Errorf("required input %q for pipeline is missing", k)
Expand All @@ -151,6 +168,11 @@ func validateWith(data map[string]string, inputs map[string]config.Input) (map[s
return data, nil
}

func matchValidShaChars(s string) bool {
match, _ := regexp.MatchString("^[a-fA-F0-9]+$", s)
return match
}

// Build a script to run as part of evalRun
func buildEvalRunCommand(pipeline *config.Pipeline, debugOption rune, workdir string, fragment string) []string {
script := fmt.Sprintf(`set -e%c
Expand Down Expand Up @@ -277,7 +299,7 @@ func (r *pipelineRunner) maybeDebug(ctx context.Context, fragment string, envOve
signal.Ignore(os.Interrupt)

// Populate $HOME/.ash_history with the current command so you can hit up arrow to repeat it.
if err := os.WriteFile(filepath.Join(r.config.WorkspaceDir, ".ash_history"), []byte(fragment), 0644); err != nil {
if err := os.WriteFile(filepath.Join(r.config.WorkspaceDir, ".ash_history"), []byte(fragment), 0o644); err != nil {
return fmt.Errorf("failed to write history file: %w", err)
}

Expand Down

0 comments on commit 5decd5c

Please sign in to comment.