Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pipeline): do preliminary checks for checksum invalid chars #1659

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 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 @@ -140,6 +141,16 @@ 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]) {
89luca89 marked this conversation as resolved.
Show resolved Hide resolved
return data, fmt.Errorf("checksum input %q for pipeline contains invalid characters", 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 v.Required && data[k] == "" {
return data, fmt.Errorf("required input %q for pipeline is missing", k)
Expand All @@ -149,6 +160,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 @@ -275,7 +291,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
Loading