pkg/aaparser: support parsing version like "3.0.0-beta1"

Fix #41517

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2020-10-02 17:33:52 +09:00
parent 816fbcd306
commit ee079e4692
No known key found for this signature in database
GPG key ID: 49524C6F9F638F1A
2 changed files with 17 additions and 0 deletions

View file

@ -56,6 +56,9 @@ func parseVersion(output string) (int, error) {
words := strings.Split(lines[0], " ")
version := words[len(words)-1]
// trim "-beta1" suffix from version="3.0.0-beta1" if exists
version = strings.SplitN(version, "-", 2)[0]
// split by major minor version
v := strings.Split(version, ".")
if len(v) == 0 || len(v) > 3 {

View file

@ -59,6 +59,20 @@ Copyright 2009-2012 Canonical Ltd.
`,
version: 314159,
},
{
output: `AppArmor parser version 3.0.0-beta1
Copyright (C) 1999-2008 Novell Inc.
Copyright 2009-2018 Canonical Ltd.
`,
version: 300000,
},
{
output: `AppArmor parser version 3.0.0-beta1-foo-bar
Copyright (C) 1999-2008 Novell Inc.
Copyright 2009-2018 Canonical Ltd.
`,
version: 300000,
},
}
for _, v := range versions {