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

imagebuildah: fix crash with empty RUN #5313

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions imagebuildah/stage_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1737,11 +1737,15 @@ func (s *StageExecutor) getCreatedBy(node *parser.Node, addedContentSummary stri
buildArgs := s.getBuildArgsKey()
return "/bin/sh -c #(nop) ARG " + buildArgs
case "RUN":
shArg := ""
buildArgs := s.getBuildArgsResolvedForRun()
if len(node.Original) > 4 {
shArg = node.Original[4:]
}
if buildArgs != "" {
return "|" + strconv.Itoa(len(strings.Split(buildArgs, " "))) + " " + buildArgs + " /bin/sh -c " + node.Original[4:]
return "|" + strconv.Itoa(len(strings.Split(buildArgs, " "))) + " " + buildArgs + " /bin/sh -c " + shArg
}
result := "/bin/sh -c " + node.Original[4:]
result := "/bin/sh -c " + shArg
if len(node.Heredocs) > 0 {
for _, doc := range node.Heredocs {
heredocContent := strings.TrimSpace(doc.Content)
Expand Down
15 changes: 15 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -952,3 +952,18 @@ _EOF
fi
done
}

@test "empty run statement doesn't crash" {
skip_if_no_runtime

_prefetch alpine

cd ${TEST_SCRATCH_DIR}

printf 'FROM alpine\nRUN \\\n echo && echo' > Dockerfile
run_buildah bud --pull=false --layers .

printf 'FROM alpine\nRUN\n echo && echo' > Dockerfile
run_buildah ? bud --pull=false --layers .
expect_output --substring -- "-c requires an argument"
}