scap-workbench/SOURCES/oscap_version_suffix.patch
2021-10-08 16:39:57 +00:00

42 lines
1.6 KiB
Diff

From d4a0508caf6f319b3c19ee370a24c4716eb77bcf Mon Sep 17 00:00:00 2001
From: Martin Preisler <martin@preisler.me>
Date: Thu, 9 Aug 2018 12:38:10 -0400
Subject: [PATCH] Support oscap version suffix when scanning remote
Previously we only supported versions such as 1.2.3, now we also support
1.2.3_alpha4.
---
src/OscapCapabilities.cpp | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/OscapCapabilities.cpp b/src/OscapCapabilities.cpp
index 03099fbf..c85804f5 100644
--- a/src/OscapCapabilities.cpp
+++ b/src/OscapCapabilities.cpp
@@ -50,8 +50,10 @@ void OscapCapabilities::clear()
static bool versionGreaterOrEqual(const QString& a, const QString& b)
{
- const QStringList aSplit = a.split('.');
- const QStringList bSplit = b.split('.');
+ // the first split chops off any suffix such as _alpha2
+ // we have a guarantee that _ will occur at most once in the string
+ const QStringList aSplit = a.split("_")[0].split('.');
+ const QStringList bSplit = b.split("_")[0].split('.');
// we only compare versions of the same number of components!
assert(aSplit.size() == bSplit.size());
@@ -89,7 +91,11 @@ void OscapCapabilities::parse(const QString& mmv)
const QStringList firstLine = lines[0].split(' ', QString::SkipEmptyParts);
const QString& versionCandidate = firstLine.last();
- if (!versionCandidate.contains(QRegExp("^([0-9]+\\.){2,}[0-9]+$")))
+ // Examples:
+ // 1.3.0_alpha2
+ // 0.8.0
+ // 1.2.18
+ if (!versionCandidate.contains(QRegExp("^([0-9]+\\.){2,}[0-9]+(_[a-z0-9]+)?$")))
return; // TODO: Throw exception?
mVersion = versionCandidate;