//Parse the whitelist file
496703
func parseWhitelistFile(whitelistFile string) (*vulnerabilitiesWhitelist, error) {
	whitelistYAML := vulnerabilitiesWhitelistYAML{}
	whitelist := vulnerabilitiesWhitelist{}

	//read the whitelist file
	whitelistBytes, err := ioutil.ReadFile(whitelistFile)
	if err != nil {
		return nil, fmt.Errorf("could not read file %v", err)
	}
	if err = yaml.Unmarshal(whitelistBytes, &whitelistYAML); err != nil {
		return nil, fmt.Errorf("could not unmarshal %v", err)
	}

	//Initialize the whitelist maps
	whitelist.General = make(map[string]bool)
	whitelist.Images = make(map[string]map[string]bool)

	//Populate the maps
	for _, cve := range whitelistYAML.General {
		whitelist.General[cve] = true
	}

	for image, cveList := range whitelistYAML.Images {
		whitelist.Images[image] = make(map[string]bool)
		for _, cve := range cveList {
			whitelist.Images[image][cve] = true
		}
	}

	return &whitelist, nil
}
6910
func (wl *Basic) UnmarshalJSON(in []byte) error {
	if in[0] != '"' || in[len(in)-1] != '"' {
		return errors.New("whitelist: invalid whitelist")
	}

	if wl.lock == nil {
		wl.lock = new(sync.Mutex)
	}

	wl.lock.Lock()
	defer wl.lock.Unlock()

	netString := strings.TrimSpace(string(in[1 : len(in)-1]))
	nets := strings.Split(netString, ",")

	wl.whitelist = map[string]bool{}
	for i := range nets {
		addr := strings.TrimSpace(nets[i])
		if addr == "" {
			continue
		}

		ip := net.ParseIP(addr)
		if ip == nil {
			wl.whitelist = nil
			return errors.New("whitelist: invalid IP address " + addr)
		}
		wl.whitelist[addr] = true
	}

	return nil
}
749928
func Parse(ipList string) string {
	for _, ip := range strings.Split(ipList, ",") {
		ip = strings.TrimSpace(ip)
		if IP := net.ParseIP(ip); IP != nil && IsPublicIP(IP) {
			return ip
		}
	}
	return ""
}
860453
func Parse(filename string) (RootList, error) {
	cfgMap, err := ParseToRawMap(filename)
	if err != nil {
		return nil, err
	}

	var rootList = RootList{}
	for label, entries := range cfgMap {
		root, err := LoadRoot(entries)
		if err != nil {
			return nil, err
		}

		rootList[label] = root
	}

	return rootList, nil
}
716165
func (r *Reader) parse(file *os.File) *File {
	status := &File{}

	sc := bufio.NewScanner(file)
	for sc.Scan() {
		parts := strings.Split(sc.Text(), ":")
		if len(parts) < 2 {
			continue
		}
		label := prune(parts[0])
		var err error
		switch label {
		case "Name":
			status.Name = prune(parts[1])
		case "Umask":
			if status.UMask, err = strconv.Atoi(prune(parts[1])); err != nil {

			}
		case "State":
			valuePts := strings.Split(parts[1], " ")
			if len(valuePts) == 2 {
				status.LState = prune(valuePts[0])
				state := strings.Replace(valuePts[1], "(", "", 1)
				state = strings.Replace(state, ")", "", 1)
				status.State = ProcessStatus(prune(state))
			}
		case "Tgid":
			status.Tgid = r.toInt(parts[1])
		case "Ngid":
			status.Ngid = r.toInt(parts[1])
		case "Pid":
			status.Pid = r.toInt(parts[1])
		case "PPid":
			status.PPid = r.toInt(parts[1])
		case "TracerPid":
			status.TracerPid = r.toInt(parts[1])
		case "Uid":
			status.UID = r.guid(parts[1])
		case "Gid":
			status.GID = r.guid(parts[1])
		case "FDSize":
			status.FDSize = r.toInt(parts[1])
		case "Groups":
			groups := strings.Split(parts[1], " ")
			if len(groups) == 0 {
				status.Groups = []int{0}
			} else {
				for _, group := range groups {
					if group == "" {
						continue
					}
					groupIdx := r.toInt(group)
					status.Groups = append(status.Groups, groupIdx)
				}
			}
		case "NStgid":
			status.NStgid = r.toInt(parts[1])
		case "NSpid":
			status.NSpid = r.toInt(parts[1])
		case "NSpgid":
			status.NSpgid = r.toInt(parts[1])
		case "NSsid":
			status.NSsid = r.toInt(parts[1])
		case "VmPeak":
			status.VMPeak = prune(parts[1])
		case "VmSize":
			status.VMSize = prune(parts[1])
		case "VmLck":
			status.VMLck = prune(parts[1])
		case "VmPin":
			status.VMPin = prune(parts[1])
		case "VmHWM":
			status.VMHWM = prune(parts[1])
		case "VmRSS":
			status.VMRSS = prune(parts[1])
		case "RssAnon":
			status.RssAnon = prune(parts[1])
		case "RssFile":
			status.RssFile = prune(parts[1])
		case "RssShmem":
			status.RssShmem = prune(parts[1])
		case "VmData":
			status.VMData = prune(parts[1])
		case "VmStk":
			status.VMStk = prune(parts[1])
		case "VmExe":
			status.VMExe = prune(parts[1])
		case "VmLib":
			status.VMLib = prune(parts[1])
		case "VmPTE":
			status.VMPTE = prune(parts[1])
		case "VmSwap":
			status.VMSwap = prune(parts[1])
		case "HugetlbPages":
			status.HugetlbPages = prune(parts[1])
		case "CoreDumping":
			status.CoreDumping = r.toInt(parts[1])
		case "Threads":
			status.Threads = r.toInt(parts[1])
		case "SigQ":
			valuePts := strings.Split(parts[1], "/")
			if len(valuePts) == 2 {
				status.SigQueued = r.toInt(valuePts[0])
				status.SigMax = r.toInt(valuePts[1])
			}
		case "SigPnd":
			status.SigPnd = r.toHex(parts[1])
		case "ShdPnd":
			status.ShdPnd = r.toHex(parts[1])
		case "SigBlk":
			status.SigBlk = r.toHex(parts[1])
		case "SigIgn":
			status.SigIgn = r.toHex(parts[1])
		case "SigCgt":
			status.SigCgt = r.toHex(parts[1])
		case "CapInh":
			status.CapInh = r.toHex(parts[1])
		case "CapPrm":
			status.CapPrm = r.toHex(parts[1])
		case "CapEff":
			status.CapEff = r.toHex(parts[1])
		case "CapBnd":
			status.CapBnd = r.toHex(parts[1])
		case "Seccomp":
			status.Seccomp = r.toInt(parts[1])
		case "Cpus_allowed":
			status.CpusAllowed = prune(parts[1])
		case "MemsAllowed_list":
			status.MemsAllowedList = r.toInt(parts[1])
		case "voluntary_ctxt_switches":
			status.VoluntaryCtxtSwitches = r.toInt(parts[1])
		case "nonvoluntary_ctxt_switches":
			status.NonvoluntaryCtxtSwitches = r.toInt(parts[1])
		}
	}

	return status
}
125004
func ParseFileWithChecks(fp string) (map[string]interface{}, error) {
	data, err := ioutil.ReadFile(fp)
	if err != nil {
		return nil, err
	}

	p, err := parse(string(data), fp, true)
	if err != nil {
		return nil, err
	}

	return p.mapping, nil
}
1278046
func (p *Parser) parseFilter(cur *ListNode) error {
	p.pos += len("[?(")
	p.consumeText()
Loop:
	for {
		switch p.next() {
		case eof, '\n':
			return fmt.Errorf("unterminated filter")
		case ')':
			break Loop
		}
	}
	if p.next() != ']' {
		return fmt.Errorf("unclosed array expect ]")
	}
	reg := regexp.MustCompile(`^([^!<>=]+)([!<>=]+)(.+?)$`)
	text := p.consumeText()
	text = string(text[:len(text)-2])
	value := reg.FindStringSubmatch(text)
	if value == nil {
		parser, err := parseAction("text", text)
		if err != nil {
			return err
		}
		cur.append(newFilter(parser.Root, newList(), "exists"))
	} else {
		leftParser, err := parseAction("left", value[1])
		if err != nil {
			return err
		}
		rightParser, err := parseAction("right", value[3])
		if err != nil {
			return err
		}
		cur.append(newFilter(leftParser.Root, rightParser.Root, value[2]))
	}
	return p.parseInsideAction(cur)
}
529540
func ParseFile(path string) (*Template, error) {
	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	return Parse(f, path)
}
1017187
func evalWhitelist(spkihash string) bool {
	for _, whitelisted := range whitelist {
		if strings.ToUpper(spkihash) == strings.ToUpper(whitelisted) {
			return true
		}
	}
	return false
}
1357729
func Whitelisting() echo.HandlerFunc {

	// swagger:route GET /users/{id}/whitelisting users whitelisting GetWhitelisting
	//
	// Show the user that placed the specified user in their whitelist
	//
	// You can personalize the request via query string parameters
	//
	//	Produces:
	//	- application/json
	//
	//	Security:
	//		oauth: profile:read
	//
	//	Responses:
	//		default: UsersIdWhitelisting

	return func(c echo.Context) error {
		if !rest.IsGranted("profile:read", c) {
			return rest.InvalidScopeResponse("profile:read", c)
		}
		whitelisting := c.Get("other").(*nerdz.User).Whitelisting()
		return rest.SelectFields(rest.GetUsersInfo(whitelisting), c)
	}
}
1272295
func (p *Parser) ParsePackageFiles(fileNames []string) (*PackageInfo, error) {
	return p.parsePackage(".", fileNames, nil)
}
586919
func parseList(scanner *bufio.Scanner, count int) ([]string, error) {
	got := 0
	items := make([]string, 0, count)
	for {
		if !scanner.Scan() {
			if err := scanner.Err(); err != nil {
				return nil, err
			}
			return nil, fmt.Errorf("expected either an empty line or a line with an item, unexpected EOF?")
		}
		line := scanner.Text()
		if line == "" {
			if got < count {
				return nil, fmt.Errorf("too few items (declared %d, got %d)", count, got)
			}
			break
		}
		got++
		if got > count {
			return nil, fmt.Errorf("too many items (declared %d)", count)
		}
		items = append(items, line)
	}
	return items, nil
}
1144976
func parseLoad(data string) (loads []float64, err error) {
	loads = make([]float64, 3)
	parts := strings.Fields(data)
	if len(parts) < 3 {
		return nil, fmt.Errorf("unexpected content in %s", procFilePath("loadavg"))
	}
	for i, load := range parts[0:3] {
		loads[i], err = strconv.ParseFloat(load, 64)
		if err != nil {
			return nil, fmt.Errorf("could not parse load '%s': %s", load, err)
		}
	}
	return loads, nil
}
960533
func ParseFile(path string) (Queries, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	return ParseReader(file)
}
1180259
func (mo *Mo) ParseFile(f string) {
	// Check if file exists
	info, err := os.Stat(f)
	if err != nil {
		return
	}

	// Check that isn't a directory
	if info.IsDir() {
		return
	}

	// Parse file content
	data, err := ioutil.ReadFile(f)
	if err != nil {
		return
	}

	mo.Parse(data)
}
517470
func ParseFile(file string) (*Rules, error) {
	f, err := os.Open(file)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	return Parse(f)
}
885921
func Whitelist() echo.HandlerFunc {

	// swagger:route GET /users/{id}/whitelist users whitelist GetWhitelist
	//
	// Show the whitelist of the specified user
	//
	// You can personalize the request via query string parameters
	//
	//	Produces:
	//	- application/json
	//
	//	Security:
	//		oauth: profile:read
	//
	//	Responses:
	//		default: UsersIdWhitelist

	return func(c echo.Context) error {
		if !rest.IsGranted("profile:read", c) {
			return rest.InvalidScopeResponse("profile:read", c)
		}
		whitelist := c.Get("other").(*nerdz.User).Whitelist()
		return rest.SelectFields(rest.GetUsersInfo(whitelist), c)
	}
}