Skip to content

build-binary.sh word-splits TOOLS, breaking its own documented usage #370

Closed

Description

@SDL-A1

scripts/build-binary.sh passes the tools list like this:

${TOOLS:+--build-arg "TOOLS=${TOOLS}"}

The expansion is unquoted, so its result is word-split. Its own documented
usage, in the header of the same file, is:

TOOLS="rewind_to block_info" scripts/build-binary.sh amd64

which contains a space. The likely result is that docker buildx build
receives --build-arg, TOOLS=rewind_to and a stray block_info as
separate arguments.

bash -n passes, because this is a semantic problem rather than a syntax
one, which is why the pull request's own checks did not catch it.

The default path is unaffected: TOOLS is set as an ARG inside
docker/build.Dockerfile, so the script only passes it when an operator
overrides it — exactly the documented case.

Worth confirming with the documented invocation before changing anything, in
case bash's handling of quotes inside ${parameter:+word} makes it work
after all. If it does break, the fix is to build the arguments in an array:

args=()
[ -n "${TOOLS:-}" ] && args+=(--build-arg "TOOLS=${TOOLS}")
docker buildx build "${args[@]}" ...

Arrived with #366.

Activity

  1. SDL-A1 commented on Nov 18, 2026

    @SDL-A1
    CollaboratorAuthor

    Not a defect. Tested rather than reasoned about, since the issue text asked for exactly that confirmation before changing anything.

    scripts/build-binary.sh is #!/bin/bash, and bash honours the quotes inside ${parameter:+word}:

    $ TOOLS="rewind_to block_info"
    $ printf '%s\n' ${TOOLS:+--build-arg "TOOLS=${TOOLS}"} | cat -A
    --build-arg$
    TOOLS=rewind_to block_info$
    

    Two arguments, not three. The space inside TOOLS survives because the inner quoting is real quoting rather than literal characters; the only split point is the unquoted space between --build-arg and "TOOLS=...", which is exactly the split we want.

    So the documented invocation

    TOOLS="rewind_to block_info" scripts/build-binary.sh amd64
    

    works as written. Closing with no change.

    One thing worth leaving on the record: this would be a real bug under a #!/bin/sh shebang on a shell that does not treat those inner quotes as quoting. The bash shebang is load-bearing here and should not be downgraded casually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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