Skip to content

Commit

Permalink
Merge pull request #5313 from giuseppe/fix-crash
Browse files Browse the repository at this point in the history
imagebuildah: fix crash with empty RUN
  • Loading branch information
openshift-merge-bot[bot] committed Feb 2, 2024
2 parents b850c71 + 9d516e2 commit 9333bc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions imagebuildah/stage_executor.go
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
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"
}

0 comments on commit 9333bc4

Please sign in to comment.