Skip to content

Validation block with nothing will crash the HCL parser #3100

@rcjsuen

Description

@rcjsuen

Contributing guidelines

I've found a bug and checked that ...

  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

Import v0.22.0 and try to run this code.

package main

import (
	"github.com/docker/buildx/bake"
	"github.com/docker/docker-language-server/internal/pkg/cli"
)

func main() {
	content := `variable "port" {
  default = 3000
  
  validation {
  }
}

target "base" {
  target = "base"
  args = {
    pp = port
  }
}
`
	bake.ParseFile([]byte(content), "/tmp/docker-bake.hcl")
}

Expected behaviour

panic: not bool

goroutine 1 [running]:
github.com/zclconf/go-cty/cty.Value.True({{{0x105ec1d78?, 0x1067cdb00?}}, {0x0?, 0x0?}})
        ../go/pkg/mod/github.com/zclconf/[email protected]/cty/value_ops.go:400 +0xfc
github.com/docker/buildx/bake/hclparser.(*parser).validateVariables(0x105ec1c98?, 0x1400000e80c?, 0x14000348300)
        ../go/pkg/mod/github.com/docker/[email protected]/bake/hclparser/hclparser.go:564 +0x1c0
github.com/docker/buildx/bake/hclparser.Parse({0x105ec1b10, 0x140003480f0}, {0x105ea9cb0?, 0x0?, 0x105ea9ca8?}, {0x105ddcca0, 0x140003a6300})
        ../go/pkg/mod/github.com/docker/[email protected]/bake/hclparser/hclparser.go:727 +0xf28
github.com/docker/buildx/bake.ParseFiles({0x140004bff10, 0x1, 0x7d?}, 0x0)
        ../go/pkg/mod/github.com/docker/[email protected]/bake/bake.go:347 +0x74c
github.com/docker/buildx/bake.ParseFile(...)
        ../go/pkg/mod/github.com/docker/[email protected]/bake/bake.go:397
main.main()
        ../code/docker/docker-language-server/cmd/docker-language-server/main.go:23 +0x6c
exit status 2

Actual behaviour

ParseFile should return an error or just ignore/skip validation perhaps?

Buildx version

github.com/docker/buildx v0.21.1-desktop.1 88b6978a99d8db82f2438df9b048c8197247b586

Docker info

Client:
 Version:    28.0.1
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  ai: Docker AI Agent - Ask Gordon (Docker Inc.)
    Version:  v0.9.3
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-ai
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.21.1-desktop.1
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.33.1-desktop.1
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.38
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Beta) (Docker Inc.)
    Version:  v0.1.5
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-desktop
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.27
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.16.3
    Path:     /Users/rcjsuen/.docker/cli-plugins/docker-scout
WARNING: Plugin "/Users/rcjsuen/.docker/cli-plugins/docker-harmonia" is not valid: failed to fetch metadata: fork/exec /Users/rcjsuen/.docker/cli-plugins/docker-harmonia: no such file or directory

Server:
 Containers: 6
  Running: 0
  Paused: 0
  Stopped: 6
 Images: 53
 Server Version: 28.0.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
 runc version: v1.2.4-0-g6c52b3f
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.10.14-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 14
 Total Memory: 7.653GiB
 Name: docker-desktop
 ID: 474dcb13-d3e2-4e4e-822f-7de1dc367b51
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/rcjsuen/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Builders list

NAME/NODE           DRIVER/ENDPOINT     STATUS    BUILDKIT   PLATFORMS
default             docker
 \_ default          \_ default         running   v0.20.0    linux/amd64 (+2), linux/arm64, linux/arm (+2), linux/ppc64le, (3 more)
desktop-linux*      docker
 \_ desktop-linux    \_ desktop-linux   running   v0.20.0    linux/amd64 (+2), linux/arm64, linux/arm (+2), linux/ppc64le, (3 more)

Configuration

You can also just reproduce the problem with this.

variable "port" {
  default = 3000

  validation {
  }
}
[+] Building 0.0s (1/1) FINISHED                                                                                                                 docker:desktop-linux
 => [internal] load local bake definitions                                                                                                                       0.0s
 => => reading docker-bake.hcl 59B / 59B                                                                                                                         0.0s
panic: not bool

goroutine 1 [running]:
github.com/zclconf/go-cty/cty.Value.True({{{0x104aa70b0?, 0x10608fb40?}}, {0x0?, 0x0?}})
	github.com/zclconf/[email protected]/cty/value_ops.go:400 +0xfc
github.com/docker/buildx/bake/hclparser.(*parser).validateVariables(0x1400068a3c0?, 0x1400001083c?, 0x1400000e768)
	github.com/docker/buildx/bake/hclparser/hclparser.go:563 +0x1cc
github.com/docker/buildx/bake/hclparser.Parse({0x104aa66c0, 0x1400000e180}, {0x104a6f320?, 0x1400055e1b0?, 0x104a6f318?}, {0x1048214c0, 0x1400055e1e0})
	github.com/docker/buildx/bake/hclparser/hclparser.go:726 +0xf24
github.com/docker/buildx/bake.ParseFiles({0x1400055e180, 0x1, 0x47?}, 0x1400055e1b0)
	github.com/docker/buildx/bake/bake.go:346 +0x754
github.com/docker/buildx/bake.ReadTargets({0x10460b9a0?, 0x1400055e1b0?}, {0x1400055e180?, 0x13?, 0x1?}, {0x14000616360, 0x1, 0x10608fb40?}, {0x0, 0x0, ...}, ...)
	github.com/docker/buildx/bake/bake.go:196 +0x50
github.com/docker/buildx/commands.runBake({0x104aa61d8, 0x1400042a4b0}, {0x104acee60, 0x1400014a640}, {0x10608fb40, 0x0, _}, {{0x10608fb40, 0x0, 0x0}, ...}, ...)
	github.com/docker/buildx/commands/bake.go:216 +0x1210
github.com/docker/buildx/commands.bakeCmd.func1(0x14000156908, {0x10608fb40, 0x0, 0x0})
	github.com/docker/buildx/commands/bake.go:456 +0x264
github.com/docker/cli/cli-plugins/plugin.RunPlugin.func1.1.2(0x14000156908, {0x10608fb40, 0x0, 0x0})
	github.com/docker/[email protected]+incompatible/cli-plugins/plugin/plugin.go:65 +0x68
github.com/spf13/cobra.(*Command).execute(0x14000156908, {0x140006234f0, 0x0, 0x0})
	github.com/spf13/[email protected]/command.go:985 +0x834
github.com/spf13/cobra.(*Command).ExecuteC(0x140002aa008)
	github.com/spf13/[email protected]/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:1041
github.com/docker/cli/cli-plugins/plugin.RunPlugin(0x1400014a640, 0x14000156308, {{0x103e09632, 0x5}, {0x103e13af0, 0xb}, {0x104334f90, 0x11}, {0x0, 0x0}, ...})
	github.com/docker/[email protected]+incompatible/cli-plugins/plugin/plugin.go:80 +0x138
main.runPlugin(0x1400014a640)
	github.com/docker/buildx/cmd/buildx/main.go:68 +0xbc
main.run(0x1400014a640)
	github.com/docker/buildx/cmd/buildx/main.go:82 +0xf0
main.main()
	github.com/docker/buildx/cmd/buildx/main.go:92 +0x7c

Build logs


Additional info

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions