From ecd3baca25918936ffdda5dec9c55314b96a9c3b Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 2 Oct 2020 17:33:52 +0900 Subject: [PATCH 1/2] pkg/aaparser: support parsing version like "3.0.0-beta1" Fix #41517 Signed-off-by: Akihiro Suda (cherry picked from commit ee079e4692c26417eb4c711a1e489203624a6972) Signed-off-by: Sebastiaan van Stijn --- pkg/aaparser/aaparser.go | 3 +++ pkg/aaparser/aaparser_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/aaparser/aaparser.go b/pkg/aaparser/aaparser.go index 9c12e8db8d..50ada7f788 100644 --- a/pkg/aaparser/aaparser.go +++ b/pkg/aaparser/aaparser.go @@ -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 { diff --git a/pkg/aaparser/aaparser_test.go b/pkg/aaparser/aaparser_test.go index 6d1f737702..64ec814729 100644 --- a/pkg/aaparser/aaparser_test.go +++ b/pkg/aaparser/aaparser_test.go @@ -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 { From 88eec2e811d620fe88b4859dee64d064fae37356 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 8 Oct 2020 15:39:52 -0700 Subject: [PATCH 2/2] Also trim "~..." from AppArmor versions Signed-off-by: Tianon Gravi (cherry picked from commit 654cad4d9dc4e87d72beb110032b61d4dfc963e4) Signed-off-by: Sebastiaan van Stijn --- pkg/aaparser/aaparser.go | 2 ++ pkg/aaparser/aaparser_test.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/pkg/aaparser/aaparser.go b/pkg/aaparser/aaparser.go index 50ada7f788..2b5a2605f9 100644 --- a/pkg/aaparser/aaparser.go +++ b/pkg/aaparser/aaparser.go @@ -58,6 +58,8 @@ func parseVersion(output string) (int, error) { // trim "-beta1" suffix from version="3.0.0-beta1" if exists version = strings.SplitN(version, "-", 2)[0] + // also trim "~..." suffix used historically (https://gitlab.com/apparmor/apparmor/-/commit/bca67d3d27d219d11ce8c9cc70612bd637f88c10) + version = strings.SplitN(version, "~", 2)[0] // split by major minor version v := strings.Split(version, ".") diff --git a/pkg/aaparser/aaparser_test.go b/pkg/aaparser/aaparser_test.go index 64ec814729..cf9280f5f5 100644 --- a/pkg/aaparser/aaparser_test.go +++ b/pkg/aaparser/aaparser_test.go @@ -43,6 +43,14 @@ Copyright 2009-2012 Canonical Ltd. `, version: 205000, }, + { + output: `AppArmor parser version 2.2.0~rc2 +Copyright (C) 1999-2008 Novell Inc. +Copyright 2009-2012 Canonical Ltd. + +`, + version: 202000, + }, { output: `AppArmor parser version 2.9.95 Copyright (C) 1999-2008 Novell Inc.