Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fuzzer for frontend dockerfile parser #1813

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ clean: FORCE
test:
./hack/test integration gateway dockerfile

fuzz:
./hack/fuzz

lint:
./hack/lint

Expand Down
15 changes: 15 additions & 0 deletions hack/dockerfiles/fuzz.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.15-alpine
ENV DEBIAN_FRONTEND=noninteractive

RUN mkdir /root/src
ENV GOPATH /root/go
ENV GOROOT /usr/local/go
ENV PATH $PATH:/usr/local/go/bin

RUN apk add --no-cache git mercurial \
&& go get -u github.com/dvyukov/go-fuzz/go-fuzz \
github.com/dvyukov/go-fuzz/go-fuzz-build \
github.com/moby/buildkit \
&& apk del git mercurial
#RUN cd $GOPATH/src/github.com/moby/buildkit/util/testutil/fuzz \
# && $GOPATH/bin/go-fuzz-build && $GOPATH/bin/go-fuzz
3 changes: 3 additions & 0 deletions hack/fuzz
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

cd hack/dockerfiles && sudo docker build -f fuzz.Dockerfile .
17 changes: 17 additions & 0 deletions util/testutil/fuzz/fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build gofuzz

package fuzz

import (
"bytes"

"github.com/moby/buildkit/frontend/dockerfile/parser"
)

func Fuzz(data []byte) int {
_, err := parser.Parse(bytes.NewReader(data))
if err != nil {
return 0
}
return 1
}