File: fuzz.go

package info (click to toggle)
golang-github-miekg-dns 1.1.68-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 1,260 kB
  • sloc: makefile: 3
file content (33 lines) | stat: -rw-r--r-- 552 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//go:build fuzz
// +build fuzz

package dns

import "strings"

func Fuzz(data []byte) int {
	msg := new(Msg)

	if err := msg.Unpack(data); err != nil {
		return 0
	}
	if _, err := msg.Pack(); err != nil {
		return 0
	}

	return 1
}

func FuzzNewRR(data []byte) int {
	str := string(data)
	// Do not fuzz lines that include the $INCLUDE keyword and hint the fuzzer
	// at avoiding them.
	// See GH#1025 for context.
	if strings.Contains(strings.ToUpper(str), "$INCLUDE") {
		return -1
	}
	if _, err := NewRR(str); err != nil {
		return 0
	}
	return 1
}