final bad try

This commit is contained in:
vovuas2003 2026-05-06 18:08:22 +03:00
parent b540edbe1e
commit fa5e0287e5
7 changed files with 106 additions and 1 deletions

39
golang-fuzz/auth_fuzz.go Normal file
View file

@ -0,0 +1,39 @@
package my_golang_fuzz
import (
"bytes"
"linux-auth/internal/auth"
"linux-auth/internal/db"
)
func Fuzz(data []byte) int {
if err := db.Init("test_data.db"); err != nil {
return -1
}
defer db.Close()
parts := bytes.SplitN(data, []byte{0}, 2)
if len(parts) != 2 {
return 0
}
username := string(parts[0])
password := string(parts[1])
ok, err := auth.Authenticate(username, password)
if err != nil {
return -1
}
if ok {
if (username == "admin" && password == "admin123") ||
(username == "user1" && password == "password1") {
return 1
}
return -1
}
return 1
}

View file

@ -0,0 +1,38 @@
// Code generated by golang-fuzz; DO NOT EDIT.
package my_golang_fuzz
import (
"os"
"path/filepath"
"testing"
)
func Fuzz_(f *testing.F) {
loadTestCases(f)
f.Fuzz(func(_ *testing.T, input []byte) { Fuzz(input) })
}
func loadTestCases(f *testing.F) {
dir, err := os.ReadDir(`corpus`)
if err != nil {
f.Logf(`Running without adding corpus: %s`, err)
return
}
if len(dir) == 0 {
f.Log(`Running without adding corpus: directory is empty`)
}
for _, corpus := range dir {
if corpus.IsDir() {
continue
}
input, err := os.ReadFile(filepath.Join(`corpus`, corpus.Name()))
if err != nil {
f.Logf(`Could not read corpus input %s: %s`, corpus.Name(), err)
}
f.Add(input)
}
}

View file

@ -0,0 +1,3 @@
#!/bin/bash
go install github.com/ultraware/golang-fuzz@latest

7
golang-fuzz/run_golang-fuzz.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
cp ../data/users.db test_data.db
export PATH=$PATH:$(go env GOPATH)/bin
golang-fuzz -gofuzz -run