Skip to content

Commit

Permalink
Added fuzzer for frontend dockerfile parser
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <[email protected]>
  • Loading branch information
AdamKorcz committed Nov 18, 2020
1 parent cb18878 commit 5dd4965
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
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
17 changes: 17 additions & 0 deletions hack/dockerfiles/fuzz.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get upgrade -y
RUN apt-get install wget git software-properties-common build-essential -y
RUN wget https://golang.org/dl/go1.14.9.linux-amd64.tar.gz
RUN tar -xvf go1.14.9.linux-amd64.tar.gz
RUN mv go /usr/local

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

RUN go get github.com/moby/buildkit
RUN go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
COPY fuzz.go /go/src/github.com/moby/buildkit/frontend/dockerfiles/parser/
RUN cd /go/src/github.com/moby/buildkit/frontend/dockerfiles/parser && $GOPATH/bin/go-fuzz-build && $GOPATH/bin/go-fuzz
5 changes: 5 additions & 0 deletions hack/fuzz
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cp util/testutil/fuzz/fuzz.go hack/dockerfiles/

cd hack/dockerfiles && sudo docker build -f fuzz.Dockerfile .
14 changes: 14 additions & 0 deletions util/testutil/fuzz/fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
}

0 comments on commit 5dd4965

Please sign in to comment.