mirror of https://github.com/daffainfo/nuclei.git
Changed code as per review comments
parent
2c8f5bc2e5
commit
19770d186f
|
@ -349,7 +349,7 @@ func (r *Runner) RunEnumeration() error {
|
||||||
if err := store.ValidateTemplates(r.options.Templates, r.options.Workflows); err != nil {
|
if err := store.ValidateTemplates(r.options.Templates, r.options.Workflows); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if stats.GetValue("syntax-warnings") == 0 && stats.GetValue("syntax-errors") == 0 {
|
if stats.GetValue(parsers.SyntaxErrorStats) == 0 && stats.GetValue(parsers.SyntaxWarningStats) == 0 {
|
||||||
gologger.Info().Msgf("All templates validated successfully\n")
|
gologger.Info().Msgf("All templates validated successfully\n")
|
||||||
} else {
|
} else {
|
||||||
return errors.New("encountered errors while performing template validation")
|
return errors.New("encountered errors while performing template validation")
|
||||||
|
@ -358,8 +358,8 @@ func (r *Runner) RunEnumeration() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display stats for any loaded templates syntax warnings or errors
|
// Display stats for any loaded templates syntax warnings or errors
|
||||||
stats.Display("syntax-warnings")
|
stats.Display(parsers.SyntaxWarningStats)
|
||||||
stats.Display("syntax-errors")
|
stats.Display(parsers.SyntaxErrorStats)
|
||||||
|
|
||||||
builder := &strings.Builder{}
|
builder := &strings.Builder{}
|
||||||
if r.templatesConfig != nil && r.templatesConfig.NucleiLatestVersion != "" {
|
if r.templatesConfig != nil && r.templatesConfig.NucleiLatestVersion != "" {
|
||||||
|
|
|
@ -92,12 +92,17 @@ var (
|
||||||
fieldErrorRegexp = regexp.MustCompile(`not found in`)
|
fieldErrorRegexp = regexp.MustCompile(`not found in`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SyntaxWarningStats = "syntax-warnings"
|
||||||
|
SyntaxErrorStats = "syntax-errors"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
parsedTemplatesCache = cache.New()
|
parsedTemplatesCache = cache.New()
|
||||||
|
|
||||||
stats.NewEntry("syntax-warnings", "Got %d syntax warnings for the loaded templates")
|
stats.NewEntry(SyntaxWarningStats, "Got %d syntax warnings for the loaded templates")
|
||||||
stats.NewEntry("syntax-errors", "Got %d syntax errors for the loaded templates")
|
stats.NewEntry(SyntaxErrorStats, "Got %d syntax errors for the loaded templates")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseTemplate parses a template and returns a *templates.Template structure
|
// ParseTemplate parses a template and returns a *templates.Template structure
|
||||||
|
@ -122,10 +127,10 @@ func ParseTemplate(templatePath string) (*templates.Template, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errString := err.Error()
|
errString := err.Error()
|
||||||
if !fieldErrorRegexp.MatchString(errString) {
|
if !fieldErrorRegexp.MatchString(errString) {
|
||||||
stats.Increment("syntax-errors")
|
stats.Increment(SyntaxErrorStats)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
stats.Increment("syntax-warnings")
|
stats.Increment(SyntaxWarningStats)
|
||||||
if ShouldValidate {
|
if ShouldValidate {
|
||||||
gologger.Error().Msgf("Syntax warnings for template %s: %s", templatePath, err)
|
gologger.Error().Msgf("Syntax warnings for template %s: %s", templatePath, err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -61,11 +61,10 @@ func (s *Storage) NewEntry(name, description string) {
|
||||||
func (s *Storage) Increment(name string) {
|
func (s *Storage) Increment(name string) {
|
||||||
s.mutex.RLock()
|
s.mutex.RLock()
|
||||||
data, ok := s.data[name]
|
data, ok := s.data[name]
|
||||||
if !ok {
|
|
||||||
s.mutex.RUnlock()
|
s.mutex.RUnlock()
|
||||||
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.mutex.RUnlock()
|
|
||||||
|
|
||||||
atomic.AddInt64(&data.value, 1)
|
atomic.AddInt64(&data.value, 1)
|
||||||
}
|
}
|
||||||
|
@ -74,11 +73,10 @@ func (s *Storage) Increment(name string) {
|
||||||
func (s *Storage) Display(name string) {
|
func (s *Storage) Display(name string) {
|
||||||
s.mutex.RLock()
|
s.mutex.RLock()
|
||||||
data, ok := s.data[name]
|
data, ok := s.data[name]
|
||||||
if !ok {
|
|
||||||
s.mutex.RUnlock()
|
s.mutex.RUnlock()
|
||||||
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.mutex.RUnlock()
|
|
||||||
|
|
||||||
dataValue := atomic.LoadInt64(&data.value)
|
dataValue := atomic.LoadInt64(&data.value)
|
||||||
if dataValue == 0 {
|
if dataValue == 0 {
|
||||||
|
@ -91,11 +89,10 @@ func (s *Storage) Display(name string) {
|
||||||
func (s *Storage) GetValue(name string) int64 {
|
func (s *Storage) GetValue(name string) int64 {
|
||||||
s.mutex.RLock()
|
s.mutex.RLock()
|
||||||
data, ok := s.data[name]
|
data, ok := s.data[name]
|
||||||
if !ok {
|
|
||||||
s.mutex.RUnlock()
|
s.mutex.RUnlock()
|
||||||
|
if !ok {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
s.mutex.RUnlock()
|
|
||||||
|
|
||||||
dataValue := atomic.LoadInt64(&data.value)
|
dataValue := atomic.LoadInt64(&data.value)
|
||||||
return dataValue
|
return dataValue
|
||||||
|
|
Loading…
Reference in New Issue