Skip to content

Commit

Permalink
Merge pull request #3 from wneessen/fuzzing
Browse files Browse the repository at this point in the history
Added fuzzing test for Atoi
  • Loading branch information
wneessen authored Oct 18, 2022
2 parents 8142010 + cea18bb commit 911dde4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.15, 1.16, 1.17, 1.18]
go: [1.17, 1.18, 1.19]
steps:
- name: Checkout Code
uses: actions/checkout@master

- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Run Tests
run: |
go test -v -race --coverprofile=coverage.coverprofile --covermode=atomic ./...
- name: Upload coverage to Codecov
if: success() && matrix.go == 1.18 && matrix.os == 'ubuntu-latest'
if: success() && matrix.go == 1.19 && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
11 changes: 7 additions & 4 deletions .github/workflows/fuzzing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.19]
os: [ubuntu-latest]
go: [1.18, 1.19]
steps:
- name: Checkout Code
uses: actions/checkout@master

- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Run Fuzzing Tests
run: |
go test -v -race -fuzz=. --fuzztime=10s . && go test -v -race -fuzz=. --fuzztime=10s ./rfc3164 && go test -v -race -fuzz=. --fuzztime=10s ./rfc5424
go version && go test -v -race -fuzz=. --fuzztime=10s . && go test -v -race -fuzz=. --fuzztime=10s ./rfc3164 && go test -v -race -fuzz=. --fuzztime=10s ./rfc5424
26 changes: 26 additions & 0 deletions common_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
//
// SPDX-License-Identifier: MI

//go:build go1.18
// +build go1.18

package parsesyslog

import (
"testing"
)

// FuzzAtoi performs a fuzzing test on Atoi
func FuzzAtoi(f *testing.F) {
tests := [][]byte{[]byte("1"), []byte("123"), []byte("255"), []byte("-1"), []byte("A")}
for _, t := range tests {
f.Add(t)
}
f.Fuzz(func(t *testing.T, ns []byte) {
_, err := Atoi(ns)
if err != nil {
return
}
})
}

0 comments on commit 911dde4

Please sign in to comment.