Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/go/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,11 @@ GO_TOOLS="\
if [ "${INSTALL_GO_TOOLS}" = "true" ]; then
echo "Installing common Go tools..."
export PATH=${TARGET_GOROOT}/bin:${PATH}
mkdir -p /tmp/gotools /usr/local/etc/vscode-dev-containers ${TARGET_GOPATH}/bin
cd /tmp/gotools
export GOPATH=/tmp/gotools
export GOCACHE=/tmp/gotools/cache
export GOCACHE=${GOPATH}/cache

mkdir -p ${GOPATH} /usr/local/etc/vscode-dev-containers ${TARGET_GOPATH}/bin
cd ${GOPATH}

# Use go get for versions of go under 1.16
go_install_command=install
Expand All @@ -316,10 +317,9 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then

(echo "${GO_TOOLS}" | xargs -n 1 go ${go_install_command} -v )2>&1 | tee -a /usr/local/etc/vscode-dev-containers/go.log

# Move Go tools into path and clean up
if [ -d /tmp/gotools/bin ]; then
mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/
rm -rf /tmp/gotools
# Move Go tools into path
if [ -d "${GOPATH}/bin" ]; then
mv ${GOPATH}/bin/* ${TARGET_GOPATH}/bin/
fi

# Install golangci-lint from precompiled binares
Expand All @@ -332,6 +332,9 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b "${TARGET_GOPATH}/bin" "v${GOLANGCILINT_VERSION}"
fi

# Remove Go tools temp directory
rm -rf ${GOPATH}
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm -rf ${GOPATH} is unquoted and unguarded. Since this runs under set -e and is now unconditional, it’s safer to use rm -rf -- "${GOPATH}" and optionally add a defensive check (e.g., non-empty and expected /tmp/... prefix) to avoid accidental deletion if GOPATH is ever changed/overridden.

Suggested change
rm -rf ${GOPATH}
if [ -n "${GOPATH}" ] && [[ "${GOPATH}" == /tmp/gotools* ]]; then
rm -rf -- "${GOPATH}"
fi

Copilot uses AI. Check for mistakes.
fi


Expand Down