aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/opencontainers/runc/libcontainer/user/user_fuzzer.go
blob: 8c9bb5df39c2a9395902d249b5eddda4eb6a9de7 (plain)
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
34
35
36
37
38
39
40
41
42
// +build gofuzz

package user

import (
	"io"
	"strings"
)

func IsDivisbleBy(n int, divisibleby int) bool {
	return (n % divisibleby) == 0
}

func FuzzUser(data []byte) int {
	if len(data) == 0 {
		return -1
	}
	if !IsDivisbleBy(len(data), 5) {
		return -1
	}

	var divided [][]byte

	chunkSize := len(data) / 5

	for i := 0; i < len(data); i += chunkSize {
		end := i + chunkSize

		divided = append(divided, data[i:end])
	}

	_, _ = ParsePasswdFilter(strings.NewReader(string(divided[0])), nil)

	var passwd, group io.Reader

	group = strings.NewReader(string(divided[1]))
	_, _ = GetAdditionalGroups([]string{string(divided[2])}, group)

	passwd = strings.NewReader(string(divided[3]))
	_, _ = GetExecUser(string(divided[4]), nil, passwd, group)
	return 1
}