Skip to content

Commit aebf411

Browse files
committed
fix: panic in threatbook
close #57
1 parent f31073a commit aebf411

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

grab/threatbook.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func NewThreatBookCrawler() Grabber {
4444
client.SetCommonHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6")
4545

4646
return &ThreatBookCrawler{
47-
log: golog.Child("[ThreatBook-Vuln]"),
47+
log: golog.Child("[threatbook]"),
4848
client: client,
4949
}
5050
}
@@ -104,7 +104,6 @@ func (t *ThreatBookCrawler) getVulnInfoFromFeed(ctx context.Context, rss *gofeed
104104
doc.Find(`td:contains('交互要求') + td`).Text(),
105105
doc.Find(`td:contains('威胁类型') + td`).Text(),
106106
}
107-
t.log.Debugf("%+v", vuln)
108107
vuln.Creator = t
109108
return &vuln, nil
110109
}
@@ -118,24 +117,25 @@ func (t *ThreatBookCrawler) ProviderInfo() *Provider {
118117
}
119118

120119
func (t *ThreatBookCrawler) GetUpdate(ctx context.Context, pageLimit int) ([]*VulnInfo, error) {
121-
ctx, cancel := context.WithTimeout(ctx, 10*time.Second) // 增加超时
120+
ctx, cancel := context.WithTimeout(ctx, 60*time.Second) // 增加超时
122121
defer cancel()
123122
fp := gofeed.NewParser()
124123
feed, err := fp.ParseURLWithContext(ThreatbookUrl, ctx)
125124
if err != nil {
126-
t.log.Errorf("Error in Parsing URL: %v, please check it", ThreatbookUrl)
125+
t.log.Errorf("error parsing %v", ThreatbookUrl)
127126
return nil, err
128127
}
129128
allVulns := getAllVulnItems(feed)
130-
numOfVuln := len(allVulns)
131-
t.log.Debugf("===GET %d vulns===", numOfVuln)
132-
133129
// 开始判断漏洞重要性,组装漏洞信息
134130
var results []*VulnInfo
135131

136132
for _, v := range allVulns {
137-
t.log.Debugf("Parsing %v at %v", v.Title, v.Link)
138-
vuln, _ := t.getVulnInfoFromFeed(ctx, v)
133+
t.log.Debugf("parsing %v at %v", v.Title, v.Link)
134+
vuln, err := t.getVulnInfoFromFeed(ctx, v)
135+
if err != nil {
136+
t.log.Error(err)
137+
continue
138+
}
139139
results = append(results, vuln)
140140
}
141141

0 commit comments

Comments
 (0)