Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: code format (including indentation and comment) #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func getDefaultConfig() (*Config, error) {

func loadConfigFile(configPath string) (*Config, error) {
var (
config *Config = &Config{}
config = &Config{}
data []byte
err error
)
Expand Down
4 changes: 2 additions & 2 deletions core/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func getBootId() ([]byte, error) {
return bootId, nil
}

// Acquires a shared lock on the file.
// LockFile Acquires a shared lock on the file.
func (f *Flock) LockFile() error {
f.m.Lock()
defer f.m.Unlock()
Expand All @@ -51,7 +51,7 @@ func (f *Flock) LockFile() error {
return nil
}

// Releases the lock on the file.
// UnlockFile Releases the lock on the file.
func (f *Flock) UnlockFile() error {
f.m.Lock()
defer f.m.Unlock()
Expand Down
9 changes: 4 additions & 5 deletions core/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewMatchFile(path string) MatchFile {
path = filepath.ToSlash(path)
_, filename := filepath.Split(path)
extension := filepath.Ext(path)
// contents, _ := ioutil.ReadFile(path)

return MatchFile{
Path: path,
Expand All @@ -29,7 +28,7 @@ func NewMatchFile(path string) MatchFile {
}
}

// IsSkippableFile Checks if the path is blacklisted
// IsSkippableDir Checks if the path is blacklisted
func IsSkippableDir(path string, baseDir string) bool {
hostMountPath := *session.Options.HostMountPath
if hostMountPath != "" {
Expand Down Expand Up @@ -92,8 +91,8 @@ func ContainsBlacklistedString(input []byte) bool {
return false
}

//// GetMatchingFiles Return the list of all applicable files inside the given directory for scanning
//func GetMatchingFiles(dir string, baseDir string) (*bytes.Buffer, *bytes.Buffer, error) {
// // GetMatchingFiles Return the list of all applicable files inside the given directory for scanning
// func GetMatchingFiles(dir string, baseDir string) (*bytes.Buffer, *bytes.Buffer, error) {
// findCmd := "find " + dir
// for _, skippableExt := range session.Config.BlacklistedExtensions {
// findCmd += " -not -name \"*" + skippableExt + "\""
Expand All @@ -110,7 +109,7 @@ func ContainsBlacklistedString(input []byte) bool {
// GetSession().Log.Info("find command: %s", findCmd)
//
// return ExecuteCommand(findCmd)
//}
// }

// UpdateDirsPermissionsRW Update permissions for dirs in container images, so that they can be properly deleted
func UpdateDirsPermissionsRW(dir string) {
Expand Down
2 changes: 1 addition & 1 deletion core/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
)

func (s *Session) Start() {
rand.Seed(time.Now().Unix())
rand.New(rand.NewSource(time.Now().Unix()))

s.InitLogger()
s.InitThreads()
Expand Down
4 changes: 2 additions & 2 deletions core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ func GetTmpDir(imageName string) (string, error) {
dir := *session.Options.TempDirectory
tempPath := filepath.Join(dir, "Deepfence", TempDirSuffix, scanId)

//if runtime.GOOS == "windows" {
// if runtime.GOOS == "windows" {
// tempPath = dir + "\temp\Deepfence\SecretScanning\df_" + scanId
//}
// }

completeTempPath := path.Join(tempPath, ExtractedImageFilesDir)

Expand Down
4 changes: 4 additions & 0 deletions signature/hs_pattens.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

// Build hyperscan Databases for matching different parts in the beginning
// This can be used for repeated scanning

func BuildHsDb() {
for _, part := range []string{ContentsPart, FilenamePart, PathPart, ExtPart} {
core.GetSession().Log.Info("Creating hyperscan database for %s", part)
Expand All @@ -27,6 +28,7 @@ func BuildHsDb() {
// @returns
// []*hyperscan.Pattern - List of hyperscan patterns
// error - Errors if any. Otherwise, returns nil

func CreateHsPatterns(part string) ([]*hyperscan.Pattern, error) {
var hsPatterns []*hyperscan.Pattern

Expand Down Expand Up @@ -56,6 +58,7 @@ func CreateHsPatterns(part string) ([]*hyperscan.Pattern, error) {
// hsPatterns - List of hyperscan patterns
// @returns
// BlockDatabase - Hyperscan database for the given list of patterns

func CreateHsDb(hsPatterns []*hyperscan.Pattern) hyperscan.BlockDatabase {
hyperscanBlockDb, err := hyperscan.NewBlockDatabase(hsPatterns...)
if err != nil {
Expand All @@ -71,6 +74,7 @@ func CreateHsDb(hsPatterns []*hyperscan.Pattern) hyperscan.BlockDatabase {
// hsIOData - Metadata containing the contents being matched, filename, layerID etc.
// @returns
// Error - Errors if any. Otherwise, returns nil

func RunHyperscan(hyperscanBlockDb hyperscan.BlockDatabase, hsIOData HsInputOutputData) error {
hyperscanScratch, err := hyperscan.NewScratch(hyperscanBlockDb)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion signature/signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
)

// Data structure for passing inputs and getting outputs for hyperscan

type HsInputOutputData struct {
inputData []byte
// Avoids extra memory during blacklist comparison, reduces memory pressure
Expand Down Expand Up @@ -64,6 +65,7 @@ func init() {
// layerID - layer ID of this file in the container image
// @returns
// []output.SecretFound - List of all secrets found

func MatchSimpleSignatures(path string, filename string, extension string, layerID string, numSecrets *uint) []output.SecretFound {
var tempSecretsFound []output.SecretFound
var matchingPart string
Expand Down Expand Up @@ -99,6 +101,7 @@ func MatchSimpleSignatures(path string, filename string, extension string, layer
// @returns
// []output.SecretFound - List of all secrets found
// Error - Errors if any. Otherwise, returns nil

func MatchPatternSignatures(contents []byte, path string, filename string, extension string, layerID string,
numSecrets *uint, matchedRuleSet map[uint]uint) ([]output.SecretFound, error) {
var tempSecretsFound []output.SecretFound
Expand Down Expand Up @@ -152,6 +155,7 @@ func MatchPatternSignatures(contents []byte, path string, filename string, exten
// store them in appropriate maps
// @parameters
// configSignatures - Extracted patterns from signature config file

func ProcessSignatures(configSignatures []core.ConfigSignature) {
var simpleContentSignatures []core.ConfigSignature
var simpleExtSignatures []core.ConfigSignature
Expand Down Expand Up @@ -418,7 +422,7 @@ func printMatchedSignatures(sid int, from, to int, hsIOData HsInputOutputData) (
}

coloredMatch := fmt.Sprintf("%s%s%s\n", inputData[start:from], color.RedString(string(inputData[from:to])), inputData[to:end])
//core.GetSession().Log.Info("%s%s%s\n", inputData[start:from], color.RedString(string(inputData[from:to])), inputData[to:end])
// core.GetSession().Log.Info("%s%s%s\n", inputData[start:from], color.RedString(string(inputData[from:to])), inputData[to:end])
core.GetSession().Log.Info(coloredMatch)

secret := output.SecretFound{
Expand Down Expand Up @@ -474,6 +478,7 @@ func calculateSeverity(inputMatch []byte, severity string, severityScore float64
}

// Find min of 2 int values

func Min(value_0, value_1 int) int {
if value_0 < value_1 {
return value_0
Expand All @@ -482,6 +487,7 @@ func Min(value_0, value_1 int) int {
}

// Find max of 2 int values

func Max(value_0, value_1 int) int {
if value_0 > value_1 {
return value_0
Expand Down