imagebuildah: fix crash with empty RUN
fix a crash when RUN is executed without any argument. Closes: https://github.com/containers/buildah/issues/5312 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
b850c711ff
commit
9d516e22e3
|
@ -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 buildArgs != "" {
|
||||
return "|" + strconv.Itoa(len(strings.Split(buildArgs, " "))) + " " + buildArgs + " /bin/sh -c " + node.Original[4:]
|
||||
if len(node.Original) > 4 {
|
||||
shArg = node.Original[4:]
|
||||
}
|
||||
result := "/bin/sh -c " + node.Original[4:]
|
||||
if buildArgs != "" {
|
||||
return "|" + strconv.Itoa(len(strings.Split(buildArgs, " "))) + " " + buildArgs + " /bin/sh -c " + shArg
|
||||
}
|
||||
result := "/bin/sh -c " + shArg
|
||||
if len(node.Heredocs) > 0 {
|
||||
for _, doc := range node.Heredocs {
|
||||
heredocContent := strings.TrimSpace(doc.Content)
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue