Skip to content

Commit 9898d2c

Browse files
authored
fix(fetcher/exploitdb): fill in nil even if Document etc. is not found (#158)
1 parent 073fce1 commit 9898d2c

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

fetcher/exploitdb.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,19 @@ func joinExploits(toCVEs map[string][]string, toDocument map[string]models.Docum
385385
if len(cves) > 0 {
386386
for _, cve := range cves {
387387
toExploits[id] = append(toExploits[id], models.Exploit{
388-
ExploitType: models.OffensiveSecurityType,
389-
ExploitUniqueID: id,
390-
URL: fmt.Sprintf("https://www.exploit-db.com/exploits/%s", id),
391-
CveID: cve,
388+
ExploitType: models.OffensiveSecurityType,
389+
ExploitUniqueID: id,
390+
URL: fmt.Sprintf("https://www.exploit-db.com/exploits/%s", id),
391+
CveID: cve,
392+
OffensiveSecurity: &models.OffensiveSecurity{},
392393
})
393394
}
394395
} else {
395396
toExploits[id] = append(toExploits[id], models.Exploit{
396-
ExploitType: models.OffensiveSecurityType,
397-
ExploitUniqueID: id,
398-
URL: fmt.Sprintf("https://www.exploit-db.com/exploits/%s", id),
397+
ExploitType: models.OffensiveSecurityType,
398+
ExploitUniqueID: id,
399+
URL: fmt.Sprintf("https://www.exploit-db.com/exploits/%s", id),
400+
OffensiveSecurity: &models.OffensiveSecurity{},
399401
})
400402
}
401403
}
@@ -548,9 +550,6 @@ func joinExploits(toCVEs map[string][]string, toDocument map[string]models.Docum
548550
continue
549551
}
550552
for i := range es {
551-
if es[i].OffensiveSecurity == nil {
552-
es[i].OffensiveSecurity = &models.OffensiveSecurity{}
553-
}
554553
es[i].OffensiveSecurity.GHDB = &models.GHDB{
555554
Link: ghdb.Link,
556555
Category: ghdb.Category,

fetcher/exploitdb_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ func Test_joinExploits(t *testing.T) {
8181
},
8282
want: []models.Exploit{
8383
{
84-
ExploitType: models.OffensiveSecurityType,
85-
ExploitUniqueID: "0",
86-
URL: "https://www.exploit-db.com/exploits/0",
87-
CveID: "CVE-0000-0000",
84+
ExploitType: models.OffensiveSecurityType,
85+
ExploitUniqueID: "0",
86+
URL: "https://www.exploit-db.com/exploits/0",
87+
CveID: "CVE-0000-0000",
88+
OffensiveSecurity: &models.OffensiveSecurity{},
8889
},
8990
{
9091
ExploitType: models.OffensiveSecurityType,

models/exploit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type OffensiveSecurity struct {
5151
GHDB *GHDB `json:"ghdb,omitempty"`
5252
}
5353

54+
// Base :
5455
type Base struct {
5556
FileURL string `gorm:"type:varchar(255)" json:"file_url"`
5657
Description string `gorm:"type:text" json:"description"`

0 commit comments

Comments
 (0)