Skip to content

extractHeadlingArgsFromNode incorrectly uses host BuiltinArgDefaults #322

Description

@isaac-sec

extractHeadlingArgsFromNode creates headling args using a new temporary builder. However, if the current builder's BuiltinArgDefaults differ from the host's defaults (such as when passing --platform to buildah, which overrides TARGET* args after calling NewBuilder()), the resulting headling args contain the wrong values.

The function should instead copy the current builder's BuiltinArgDefaults into the temporary builder before trying to construct the headling args. The following patch should fix this:

--- a/builder.go
+++ b/builder.go
@@ -6,6 +6,7 @@ import (
        "fmt"
        "io"
        "log"
+       "maps"
        "os"
        "path/filepath"
        "runtime"
@@ -418,6 +419,7 @@ func (b *Builder) extractHeadingArgsFromNode(node *parser.Node) error {

        // Use a separate builder to evaluate the heading args
        tempBuilder := NewBuilder(b.UserArgs)
+       maps.Copy(tempBuilder.BuiltinArgDefaults, b.BuiltinArgDefaults)

        // Built-in ARGs are declared implicitly in the heading and should be resolvable in its scope
        for k, v := range tempBuilder.BuiltinArgDefaults {

The test cases in podman-container-tools/buildah#6964 pass after making this change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions