FIX Update ArchLinux names

Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
This commit is contained in:
Nicolas Lamirault 2016-01-12 22:16:14 +01:00
parent 1026d69158
commit 86f810b86a
2 changed files with 19 additions and 19 deletions

View File

@ -28,7 +28,7 @@ import (
const ( const (
archLinuxCVEURL = "https://wiki.archlinux.org/api.php?action=query&titles=CVE&format=txt&prop=revisions&rvlimit=1&rvprop=content" archLinuxCVEURL = "https://wiki.archlinux.org/api.php?action=query&titles=CVE&format=txt&prop=revisions&rvlimit=1&rvprop=content"
archlinuxUpdaterFlag = "archlinuxUpdater" archLinuxUpdaterFlag = "archLinuxUpdater"
tokensRegexp = "{|}|CVF|PKG|Pkg|pkg|\\[|\\]" tokensRegexp = "{|}|CVF|PKG|Pkg|pkg|\\[|\\]"
) )
@ -37,8 +37,8 @@ type SecurityAdvisory struct {
URL string URL string
} }
// ArchCVE represents a CVE for Arch Linux // ArchLinuxCVE represents a CVE for Arch Linux
type ArchCVE struct { type ArchLinuxCVE struct {
CVEID string CVEID string
Package string Package string
DisclosureDate string DisclosureDate string
@ -49,30 +49,30 @@ type ArchCVE struct {
ASAID SecurityAdvisory ASAID SecurityAdvisory
} }
// ArchlinuxFetcher implements updater.Fetcher for the Archlinux CVE // ArchLinuxFetcher implements updater.Fetcher for the Arch Linux CVE
// (See wiki : https://wiki.archlinux.org/index.php/CVE). // (See wiki : https://wiki.archlinux.org/index.php/CVE).
type ArchlinuxFetcher struct{} type ArchLinuxFetcher struct{}
func init() { func init() {
updater.RegisterFetcher("archlinux", &ArchlinuxFetcher{}) updater.RegisterFetcher("archlinux", &ArchLinuxFetcher{})
} }
// FetchUpdate fetches vulnerability updates from the Archlinux Security Tracker. // FetchUpdate fetches vulnerability updates from the Arch Linux Security Tracker.
func (fetcher *ArchlinuxFetcher) FetchUpdate() (resp updater.FetcherResponse, err error) { func (fetcher *ArchLinuxFetcher) FetchUpdate() (resp updater.FetcherResponse, err error) {
log.Info("fetching Archlinux vulneratibilities") log.Info("fetching ArchLinux vulneratibilities")
r, err := http.Get(archLinuxCVEURL) r, err := http.Get(archLinuxCVEURL)
if err != nil { if err != nil {
log.Errorf("could not download Archlinux CVE wiki content: %s", err) log.Errorf("could not download ArchLinux CVE wiki content: %s", err)
return resp, cerrors.ErrCouldNotDownload return resp, cerrors.ErrCouldNotDownload
} }
defer r.Body.Close() defer r.Body.Close()
flag, err := database.GetFlagValue(archlinuxUpdaterFlag) flag, err := database.GetFlagValue(archLinuxUpdaterFlag)
if err != nil { if err != nil {
return resp, err return resp, err
} }
resp, err = parseArchlinuxWikiCVE(r.Body, flag) resp, err = parseArchLinuxWikiCVE(r.Body, flag)
if err != nil { if err != nil {
return resp, err return resp, err
} }
@ -80,14 +80,14 @@ func (fetcher *ArchlinuxFetcher) FetchUpdate() (resp updater.FetcherResponse, er
return resp, nil return resp, nil
} }
func parseArchlinuxWikiCVE(reader io.Reader, flag string) (resp updater.FetcherResponse, err error) { func parseArchLinuxWikiCVE(reader io.Reader, flag string) (resp updater.FetcherResponse, err error) {
scanner := bufio.NewScanner(reader) scanner := bufio.NewScanner(reader)
re := regexp.MustCompile(tokensRegexp) re := regexp.MustCompile(tokensRegexp)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
if strings.Contains(line, "{{CVE|CVE") { if strings.Contains(line, "{{CVE|CVE") {
if !strings.Contains(line, "CVE-2014-????") { if !strings.Contains(line, "CVE-2014-????") {
cve := buildArchlinuxCVE(re.ReplaceAllString(line, "")) cve := buildArchLinuxCVE(re.ReplaceAllString(line, ""))
vulnerability := &database.Vulnerability{ vulnerability := &database.Vulnerability{
ID: cve.CVEID, ID: cve.CVEID,
Link: cve.ASAID.URL, Link: cve.ASAID.URL,
@ -102,7 +102,7 @@ func parseArchlinuxWikiCVE(reader io.Reader, flag string) (resp updater.FetcherR
return resp, nil return resp, nil
} }
func buildArchlinuxCVE(line string) ArchCVE { func buildArchLinuxCVE(line string) ArchLinuxCVE {
data := strings.Split(strings.TrimSpace(line), "||") data := strings.Split(strings.TrimSpace(line), "||")
sa := SecurityAdvisory{} sa := SecurityAdvisory{}
if len(data) == 8 { if len(data) == 8 {
@ -119,7 +119,7 @@ func buildArchlinuxCVE(line string) ArchCVE {
if len(dataTitle) >= 1 { if len(dataTitle) >= 1 {
title = dataTitle[2] title = dataTitle[2]
} }
return ArchCVE{ return ArchLinuxCVE{
CVEID: title, CVEID: title,
Package: strings.Replace(strings.TrimSpace(data[1]), "|", "", -1), Package: strings.Replace(strings.TrimSpace(data[1]), "|", "", -1),
DisclosureDate: strings.TrimSpace(data[2]), DisclosureDate: strings.TrimSpace(data[2]),

View File

@ -28,8 +28,8 @@ import (
func TestArchLinuxCVEBuilder(t *testing.T) { func TestArchLinuxCVEBuilder(t *testing.T) {
line := "| {{CVE|CVE-2014-9687}} [http://www.openwall.com/lists/oss-security/2015/02/10/10 templink] || {{pkg|ecryptfs-utils}} || 2015-02-10 || <= 104-1 || 106-1 || 37d || Fixed ({{bug|44157}}) || [https://lists.archlinux.org/pipermail/arch-security/2015-March/000255.html ASA-201503-14]" line := "| {{CVE|CVE-2014-9687}} [http://www.openwall.com/lists/oss-security/2015/02/10/10 templink] || {{pkg|ecryptfs-utils}} || 2015-02-10 || <= 104-1 || 106-1 || 37d || Fixed ({{bug|44157}}) || [https://lists.archlinux.org/pipermail/arch-security/2015-March/000255.html ASA-201503-14]"
re := regexp.MustCompile(tokensRegexp) re := regexp.MustCompile(tokensRegexp)
cve := buildArchlinuxCVE(re.ReplaceAllString(line, "")) cve := buildArchLinuxCVE(re.ReplaceAllString(line, ""))
expected := ArchCVE{ expected := ArchLinuxCVE{
CVEID: "CVE-2014-9687 http://www.openwall.com/lists/oss-security/2015/02/10/10 templink", CVEID: "CVE-2014-9687 http://www.openwall.com/lists/oss-security/2015/02/10/10 templink",
Package: "ecryptfs-utils", Package: "ecryptfs-utils",
DisclosureDate: "2015-02-10", DisclosureDate: "2015-02-10",
@ -49,7 +49,7 @@ func TestArchlinuxParser(t *testing.T) {
_, filename, _, _ := runtime.Caller(0) _, filename, _, _ := runtime.Caller(0)
testFile, _ := os.Open( testFile, _ := os.Open(
path.Join(path.Dir(filename)) + "/testdata/fetcher_archlinux.txt") path.Join(path.Dir(filename)) + "/testdata/fetcher_archlinux.txt")
response, err := parseArchlinuxWikiCVE(testFile, "") response, err := parseArchLinuxWikiCVE(testFile, "")
if err != nil { if err != nil {
t.Fatalf("Error reading Arch CVE: %s %s", t.Fatalf("Error reading Arch CVE: %s %s",
testFile.Name(), err.Error()) testFile.Name(), err.Error())