...

Source file src/github.com/moby/sys/user/user_fuzzer.go

Documentation: github.com/moby/sys/user

     1  //go:build gofuzz
     2  // +build gofuzz
     3  
     4  package user
     5  
     6  import (
     7  	"io"
     8  	"strings"
     9  )
    10  
    11  func IsDivisbleBy(n int, divisibleby int) bool {
    12  	return (n % divisibleby) == 0
    13  }
    14  
    15  func FuzzUser(data []byte) int {
    16  	if len(data) == 0 {
    17  		return -1
    18  	}
    19  	if !IsDivisbleBy(len(data), 5) {
    20  		return -1
    21  	}
    22  
    23  	var divided [][]byte
    24  
    25  	chunkSize := len(data) / 5
    26  
    27  	for i := 0; i < len(data); i += chunkSize {
    28  		end := i + chunkSize
    29  
    30  		divided = append(divided, data[i:end])
    31  	}
    32  
    33  	_, _ = ParsePasswdFilter(strings.NewReader(string(divided[0])), nil)
    34  
    35  	var passwd, group io.Reader
    36  
    37  	group = strings.NewReader(string(divided[1]))
    38  	_, _ = GetAdditionalGroups([]string{string(divided[2])}, group)
    39  
    40  	passwd = strings.NewReader(string(divided[3]))
    41  	_, _ = GetExecUser(string(divided[4]), nil, passwd, group)
    42  	return 1
    43  }
    44  

View as plain text