mirror of
https://github.com/cve-search/git-vuln-finder.git
synced 2024-11-22 23:07:20 +00:00
'# FIXME: Is there a better way?': yes
This commit is contained in:
parent
335bdff4cb
commit
851d8946fd
1 changed files with 11 additions and 14 deletions
|
@ -12,6 +12,14 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
|
def tree():
|
||||||
|
"""Autovivification.
|
||||||
|
Call it a tree or call it 'patterns'.
|
||||||
|
"""
|
||||||
|
return defaultdict(tree)
|
||||||
|
|
||||||
|
|
||||||
PATTERNS_PATH = "./git_vuln_finder/patterns"
|
PATTERNS_PATH = "./git_vuln_finder/patterns"
|
||||||
|
@ -43,7 +51,7 @@ def build_pattern(pattern_file):
|
||||||
|
|
||||||
|
|
||||||
def get_patterns(patterns_path=PATTERNS_PATH):
|
def get_patterns(patterns_path=PATTERNS_PATH):
|
||||||
patterns = {}
|
patterns = tree()
|
||||||
for root, dirs, files in os.walk(patterns_path):
|
for root, dirs, files in os.walk(patterns_path):
|
||||||
path = root.split(os.sep)
|
path = root.split(os.sep)
|
||||||
for f in files:
|
for f in files:
|
||||||
|
@ -59,17 +67,6 @@ def get_patterns(patterns_path=PATTERNS_PATH):
|
||||||
severity = npath[1]
|
severity = npath[1]
|
||||||
pattern_category = f
|
pattern_category = f
|
||||||
|
|
||||||
try: # FIXME: Is there a better way?
|
|
||||||
a = patterns[lang]
|
|
||||||
except KeyError:
|
|
||||||
patterns[lang] = {}
|
|
||||||
try:
|
|
||||||
a = patterns[lang][severity]
|
|
||||||
except KeyError:
|
|
||||||
patterns[lang][severity] = {}
|
|
||||||
try:
|
|
||||||
a = patterns[lang][severity][pattern_category]
|
|
||||||
except KeyError:
|
|
||||||
rex = build_pattern(root + os.sep + f)
|
rex = build_pattern(root + os.sep + f)
|
||||||
patterns[lang][severity][pattern_category] = re.compile(rex)
|
patterns[lang][severity][pattern_category] = re.compile(rex)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue