CreMindES / whalelint

Dockerfile linter written in Go. It provides static analysis for Dockerfiles, identifying common mistakes and promotes best practices.
MIT License
12 stars 2 forks source link

Current semicolon handling method compromises rawString value in BashCommand. #9

Open CreMindES opened 3 years ago

CreMindES commented 3 years ago

The current semicolon handling - convertSemicolonsToLexItems - strategy during ParseBashCommandList is flawed, as it modifies the rawString value in the resulting BashCommands.

tymonx commented 2 years ago

It seems related. This example fails:

ARG BASE_IMAGE=alpine
ARG BASE_TAG=3.14.2

FROM $BASE_IMAGE:$BASE_TAG

RUN \
    packages="colordiff make curl wget git gcc g++ jq" && \
    if command -v apt-get >/dev/null 2>&1; then \
        apt-get update && \
        apt-get install --yes --no-install-recommends --no-upgrade \
            ${packages:+${packages}} \
            bsdmainutils \
            && \
        apt-get clean && \
        apt-get autoclean && \
        rm -rf /var/lib/apt/lists/*; \
    elif command -v apk >/dev/null 2>&1; then \
        mkdir -p /var/cache/apk && \
        ln -s /var/cache/apk /etc/apk/cache && \
        apk --no-cache update && \
        apk --no-cache add \
            ${packages:+${packages}} \
            util-linux \
            libc-dev \
            musl-dev \
            && \
        apk cache clean; \
    elif command -v dnf >/dev/null 2>&1; then \
        dnf update && \
        dnf install --assumeyes \
            ${packages:+${packages}} \
            util-linux \
            && \
        dnf clean all; \
    elif command -v zypper >/dev/null 2>&1; then \
        zypper update --no-confirm && \
        zypper install --no-confirm \
            ${packages:+${packages}} \
            util-linux \
            && \
        zypper clean --all; \
    fi

The parser.ParseBashCommand function throws a panic:

panic: runtime error: index out of range [0] with length 0 [recovered]
        panic: runtime error: index out of range [0] with length 0