Skip to content

Commit

Permalink
fix identation
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimassaguerpla committed Jun 30, 2016
1 parent 7e1d26f commit 9bd6acf
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 234 deletions.
73 changes: 36 additions & 37 deletions updater/fetchers/opensuse/opensuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@ package opensuse
import (
"fmt"
"regexp"
"strconv"
"strconv"

"github.com/coreos/clair/updater"
"github.com/coreos/clair/updater/fetchers/oval"
"github.com/coreos/clair/updater/fetchers/oval"
"github.com/coreos/pkg/capnslog"
)

var log = capnslog.NewPackageLogger("github.com/coreos/clair", "updater/fetchers/sle")

func init() {
opensuse_info := &OpenSUSE_Info{}
opensuse_info := &OpenSUSE_Info{}

updater.RegisterFetcher(opensuse_info.DistName(),
&oval.OvalFetcher{Os_info: opensuse_info})
&oval.OvalFetcher{Os_info: opensuse_info})
}

type OpenSUSE_Info struct {
}

func (f *OpenSUSE_Info) CritSystem() *regexp.Regexp {
return regexp.MustCompile(`openSUSE [^0-9]*(\d+\.\d+)[^0-9]* is installed`)
return regexp.MustCompile(`openSUSE [^0-9]*(\d+\.\d+)[^0-9]* is installed`)
}

func (f *OpenSUSE_Info) CritPackage() *regexp.Regexp {
Expand All @@ -48,7 +49,7 @@ func (f *OpenSUSE_Info) DistRegexp() *regexp.Regexp {
}

func (f *OpenSUSE_Info) OvalURI() string {
return "http://ftp.suse.com/pub/projects/security/oval/"
return "http://ftp.suse.com/pub/projects/security/oval/"
}

func (f *OpenSUSE_Info) UpdaterFlag() string {
Expand All @@ -60,43 +61,41 @@ func (f *OpenSUSE_Info) DistMinVersion() float64 {
}

func (f *OpenSUSE_Info) DistName() string {
return "opensuse"
return "opensuse"
}

func (f *OpenSUSE_Info) ParseOsVersion(comment string) string {
systemMatch := f.CritSystem().FindStringSubmatch(comment)
if len(systemMatch) < 2 {
return ""
}
osVersion := systemMatch[1]
if len(systemMatch) == 4 && systemMatch[3] != "" {
sp:= systemMatch[3]
osVersion = fmt.Sprintf("%s.%s", osVersion, sp)
}

// log.Infof("got %s as system version from: %s", osVersion, c.Comment)
return osVersion
systemMatch := f.CritSystem().FindStringSubmatch(comment)
if len(systemMatch) < 2 {
return ""
}
osVersion := systemMatch[1]
if len(systemMatch) == 4 && systemMatch[3] != "" {
sp := systemMatch[3]
osVersion = fmt.Sprintf("%s.%s", osVersion, sp)
}

// log.Infof("got %s as system version from: %s", osVersion, c.Comment)
return osVersion

}

func (f *OpenSUSE_Info) ParsePackageNameVersion(comment string) (string, string) {
packageMatch := f.CritPackage().FindStringSubmatch(comment)

if len(packageMatch) != 3 {
return "", ""
}
name := packageMatch[1]
version:= packageMatch[2]
return name, version
packageMatch := f.CritPackage().FindStringSubmatch(comment)

if len(packageMatch) != 3 {
return "", ""
}
name := packageMatch[1]
version := packageMatch[2]
return name, version
}


func (f *OpenSUSE_Info) ParseFilenameDistVersion(line string) (string, float64) {
r := f.DistRegexp().FindStringSubmatch(line)
if len(r) == 2 {
distVersion, _ := strconv.ParseFloat(r[1], 32)
return r[0], distVersion
}
return "", 0
}

func (f *OpenSUSE_Info) ParseFilenameDistVersion(line string) (string, float64) {
r := f.DistRegexp().FindStringSubmatch(line)
if len(r) == 2 {
distVersion, _ := strconv.ParseFloat(r[1], 32)
return r[0], distVersion
}
return "", 0
}
4 changes: 2 additions & 2 deletions updater/fetchers/opensuse/opensuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func TestOpenSUSEParser(t *testing.T) {

// Test parsing testdata/fetcher_opensuse_test.1.xml
testFile, _ := os.Open(path + "/testdata/fetcher_opensuse_test.1.xml")
ov := &oval.OvalFetcher{ Os_info: &OpenSUSE_Info{}}
ov := &oval.OvalFetcher{Os_info: &OpenSUSE_Info{}}
vulnerabilities, err := ov.ParseOval(testFile)
if assert.Nil(t, err) && assert.Len(t, vulnerabilities, 1) {
assert.Equal(t, "CVE-2012-2150", vulnerabilities[0].Name)
assert.Equal(t, "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-2150", vulnerabilities[0].Link)
// Severity is not defined for openSUSE
// Severity is not defined for openSUSE
assert.Equal(t, types.Unknown, vulnerabilities[0].Severity)
assert.Equal(t, `xfs_metadump in xfsprogs before 3.2.4 does not properly obfuscate file data, which allows remote attackers to obtain sensitive information by reading a generated image.`, vulnerabilities[0].Description)

Expand Down
124 changes: 62 additions & 62 deletions updater/fetchers/opensuse/testdata/fetcher_opensuse_test.1.xml
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>

<oval_definitions
xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd"
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5"
xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<generator>
<oval:product_name>Marcus Updateinfo to OVAL Converter</oval:product_name>
<oval:schema_version>5.5</oval:schema_version>
<oval:timestamp>2016-06-27T04:04:46</oval:timestamp>
</generator>
<definitions>
<definition id="oval:org.opensuse.security:def:20122150" version="1" class="vulnerability">
<metadata>
<title>CVE-2012-2150</title>
<affected family="unix">
<platform>openSUSE Leap 42.1</platform>
</affected>
<reference ref_id="CVE-2012-2150" ref_url="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-2150" source="CVE"/>
<description>xfs_metadump in xfsprogs before 3.2.4 does not properly obfuscate file data, which allows remote attackers to obtain sensitive information by reading a generated image.</description>
</metadata>
<criteria operator="AND">
<criterion test_ref="oval:org.opensuse.security:tst:2009117743" comment="openSUSE Leap 42.1 is installed"/>
<criteria operator="OR">
<criterion test_ref="oval:org.opensuse.security:tst:2009120999" comment="xfsprogs-3.2.1-5.1 is installed"/>
<criterion test_ref="oval:org.opensuse.security:tst:2009121000" comment="xfsprogs-devel-3.2.1-5.1 is installed"/>
</criteria>
</criteria>
</definition>
</definitions>
<tests>
<rpminfo_test id="oval:org.opensuse.security:tst:2009117743" version="1" comment="openSUSE-release is ==42.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<object object_ref="oval:org.opensuse.security:obj:2009031246"/>
<state state_ref="oval:org.opensuse.security:ste:2009046321"/>
</rpminfo_test>
<rpminfo_test id="oval:org.opensuse.security:tst:2009120999" version="1" comment="xfsprogs is &lt;3.2.1-5.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<object object_ref="oval:org.opensuse.security:obj:2009032555"/>
<state state_ref="oval:org.opensuse.security:ste:2009046736"/>
</rpminfo_test>
<rpminfo_test id="oval:org.opensuse.security:tst:2009121000" version="1" comment="xfsprogs-devel is &lt;3.2.1-5.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<object object_ref="oval:org.opensuse.security:obj:2009032648"/>
<state state_ref="oval:org.opensuse.security:ste:2009046736"/>
</rpminfo_test>
</tests>
<objects>
<rpminfo_object id="oval:org.opensuse.security:obj:2009032648" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<name>xfsprogs-devel</name>
</rpminfo_object>
<rpminfo_object id="oval:org.opensuse.security:obj:2009031246" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<name>openSUSE-release</name>
</rpminfo_object>
<rpminfo_object id="oval:org.opensuse.security:obj:2009032555" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<name>xfsprogs</name>
</rpminfo_object>
</objects>
<states>
<rpminfo_state id="oval:org.opensuse.security:ste:2009046736" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<evr datatype="evr_string" operation="less than">0:3.2.1-5.1</evr>
</rpminfo_state>
<rpminfo_state id="oval:org.opensuse.security:ste:2009046321" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<version operation="equals">42.1</version>
</rpminfo_state>
</states>
xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd"
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5"
xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<generator>
<oval:product_name>Marcus Updateinfo to OVAL Converter</oval:product_name>
<oval:schema_version>5.5</oval:schema_version>
<oval:timestamp>2016-06-27T04:04:46</oval:timestamp>
</generator>
<definitions>
<definition id="oval:org.opensuse.security:def:20122150" version="1" class="vulnerability">
<metadata>
<title>CVE-2012-2150</title>
<affected family="unix">
<platform>openSUSE Leap 42.1</platform>
</affected>
<reference ref_id="CVE-2012-2150" ref_url="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-2150" source="CVE"/>
<description>xfs_metadump in xfsprogs before 3.2.4 does not properly obfuscate file data, which allows remote attackers to obtain sensitive information by reading a generated image.</description>
</metadata>
<criteria operator="AND">
<criterion test_ref="oval:org.opensuse.security:tst:2009117743" comment="openSUSE Leap 42.1 is installed"/>
<criteria operator="OR">
<criterion test_ref="oval:org.opensuse.security:tst:2009120999" comment="xfsprogs-3.2.1-5.1 is installed"/>
<criterion test_ref="oval:org.opensuse.security:tst:2009121000" comment="xfsprogs-devel-3.2.1-5.1 is installed"/>
</criteria>
</criteria>
</definition>
</definitions>
<tests>
<rpminfo_test id="oval:org.opensuse.security:tst:2009117743" version="1" comment="openSUSE-release is ==42.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<object object_ref="oval:org.opensuse.security:obj:2009031246"/>
<state state_ref="oval:org.opensuse.security:ste:2009046321"/>
</rpminfo_test>
<rpminfo_test id="oval:org.opensuse.security:tst:2009120999" version="1" comment="xfsprogs is &lt;3.2.1-5.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<object object_ref="oval:org.opensuse.security:obj:2009032555"/>
<state state_ref="oval:org.opensuse.security:ste:2009046736"/>
</rpminfo_test>
<rpminfo_test id="oval:org.opensuse.security:tst:2009121000" version="1" comment="xfsprogs-devel is &lt;3.2.1-5.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<object object_ref="oval:org.opensuse.security:obj:2009032648"/>
<state state_ref="oval:org.opensuse.security:ste:2009046736"/>
</rpminfo_test>
</tests>
<objects>
<rpminfo_object id="oval:org.opensuse.security:obj:2009032648" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<name>xfsprogs-devel</name>
</rpminfo_object>
<rpminfo_object id="oval:org.opensuse.security:obj:2009031246" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<name>openSUSE-release</name>
</rpminfo_object>
<rpminfo_object id="oval:org.opensuse.security:obj:2009032555" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<name>xfsprogs</name>
</rpminfo_object>
</objects>
<states>
<rpminfo_state id="oval:org.opensuse.security:ste:2009046736" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<evr datatype="evr_string" operation="less than">0:3.2.1-5.1</evr>
</rpminfo_state>
<rpminfo_state id="oval:org.opensuse.security:ste:2009046321" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
<version operation="equals">42.1</version>
</rpminfo_state>
</states>
</oval_definitions>
53 changes: 25 additions & 28 deletions updater/fetchers/oval/oval.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,20 @@ type criterion struct {

// OvalFetcher implements updater.Fetcher.
type OvalFetcher struct {
Os_info OSInfo
Os_info OSInfo
}

type OSInfo interface {
ParsePackageNameVersion(string) (string, string)
ParseOsVersion(string) string
ParseFilenameDistVersion(string) (string, float64)
OvalURI() string
UpdaterFlag() string
DistMinVersion() float64
DistName() string
ParsePackageNameVersion(string) (string, string)
ParseOsVersion(string) string
ParseFilenameDistVersion(string) (string, float64)
OvalURI() string
UpdaterFlag() string
DistMinVersion() float64
DistName() string
}

var (

log = capnslog.NewPackageLogger("github.com/coreos/clair", "updater/fetchers/sle")
)

Expand Down Expand Up @@ -99,10 +98,10 @@ func (f *OvalFetcher) FetchUpdate(datastore database.Datastore) (resp updater.Fe

for scanner.Scan() {
line := scanner.Text()
filename, distVersion := f.Os_info.ParseFilenameDistVersion(line)
if distVersion >= f.Os_info.DistMinVersion() {
distList = append(distList, filename)
}
filename, distVersion := f.Os_info.ParseFilenameDistVersion(line)
if distVersion >= f.Os_info.DistMinVersion() {
distList = append(distList, filename)
}
}

for _, distFile := range distList {
Expand Down Expand Up @@ -140,19 +139,18 @@ func (f *OvalFetcher) ToFeatureVersions(possibilities [][]criterion) []database.
)

for _, c := range criterions {
tmp_v := f.Os_info.ParseOsVersion(c.Comment)
if tmp_v != "" {
osVersion = tmp_v
continue
}

tmp_p_name, tmp_p_version := f.Os_info.ParsePackageNameVersion(c.Comment)
if tmp_p_version != "" && tmp_p_name != "" {
featureVersion.Feature.Name = tmp_p_name
featureVersion.Version, _ = types.NewVersion(tmp_p_version)
continue
}
tmp_v := f.Os_info.ParseOsVersion(c.Comment)
if tmp_v != "" {
osVersion = tmp_v
continue
}

tmp_p_name, tmp_p_version := f.Os_info.ParsePackageNameVersion(c.Comment)
if tmp_p_version != "" && tmp_p_name != "" {
featureVersion.Feature.Name = tmp_p_name
featureVersion.Version, _ = types.NewVersion(tmp_p_version)
continue
}

log.Warningf("could not parse criteria: '%s'.", c.Comment)
}
Expand All @@ -178,7 +176,7 @@ func (f *OvalFetcher) ToFeatureVersions(possibilities [][]criterion) []database.

return featureVersionParametersArray
}
func (f* OvalFetcher) ParseOval(ovalReader io.Reader) (vulnerabilities []database.Vulnerability, err error) {
func (f *OvalFetcher) ParseOval(ovalReader io.Reader) (vulnerabilities []database.Vulnerability, err error) {
var ov oval
err = xml.NewDecoder(ovalReader).Decode(&ov)

Expand Down Expand Up @@ -241,7 +239,7 @@ func getCriterions(node criteria) [][]criterion {
var criterions []criterion

for _, c := range node.Criterions {
criterions = append(criterions, c)
criterions = append(criterions, c)
}

if node.Operator == "AND" {
Expand Down Expand Up @@ -306,4 +304,3 @@ func getPossibilities(node criteria) [][]criterion {
}
return possibilities
}

Loading

0 comments on commit 9bd6acf

Please sign in to comment.