From c46f5680ca8d911c5e83c90b73f830f4f4609686 Mon Sep 17 00:00:00 2001 From: Joerg Behrmann Date: Thu, 13 Jul 2023 11:07:03 +0200 Subject: analyze: don't warn about version spec compliant versions This commits adds version_is_valid_versionspec and uses it in analyze-compare-version.c. version_is_valid_versionspec differs from version_is_valid in that it acepts empty strings and since valid characters in a version spec version are all ASCII letters and digits as well as "-.~^", but ",_+" allowed by version_is_valid are not. Also give a more specific warning message on invalid characters. --- src/analyze/analyze-compare-versions.c | 10 +++++----- src/basic/string-util.c | 10 ++++++++++ src/basic/string-util.h | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/analyze/analyze-compare-versions.c b/src/analyze/analyze-compare-versions.c index d210fab672..94cff1853e 100644 --- a/src/analyze/analyze-compare-versions.c +++ b/src/analyze/analyze-compare-versions.c @@ -16,12 +16,12 @@ int verb_compare_versions(int argc, char *argv[], void *userdata) { assert(argv); /* We only output a warning on invalid version strings (instead of failing), since the comparison - * functions try to handle invalid strings graceful and it's still interesting to see what the + * functions try to handle invalid strings gracefully and it's still interesting to see what the * comparison result will be. */ - if (!version_is_valid(v1)) - log_warning("Version string 1 is not valid, comparing anyway: %s", v1); - if (!version_is_valid(v2)) - log_warning("Version string 2 is not valid, comparing anyway: %s", v2); + if (!version_is_valid_versionspec(v1)) + log_warning("Version string 1 contains disallowed characters, they will be treated as separators: %s", v1); + if (!version_is_valid_versionspec(v2)) + log_warning("Version string 2 contains disallowed characters, they will be treated as separators: %s", v2); if (argc == 3) { r = strverscmp_improved(v1, v2); diff --git a/src/basic/string-util.c b/src/basic/string-util.c index d3b6db9c55..7cddec712b 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -1436,3 +1436,13 @@ bool version_is_valid(const char *s) { return true; } + +bool version_is_valid_versionspec(const char *s) { + if (!filename_part_is_valid(s)) + return false; + + if (!in_charset(s, ALPHANUMERICAL "-.~^")) + return false; + + return true; +} diff --git a/src/basic/string-util.h b/src/basic/string-util.h index 52eab27fa3..f473946864 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -282,3 +282,5 @@ char *startswith_strv(const char *string, char **strv); startswith_strv(p, STRV_MAKE(__VA_ARGS__)) bool version_is_valid(const char *s); + +bool version_is_valid_versionspec(const char *s); -- cgit v1.2.3