]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: don't warn about version spec compliant versions
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 13 Jul 2023 09:07:03 +0000 (11:07 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 18 Jul 2023 14:57:15 +0000 (15:57 +0100)
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
src/basic/string-util.c
src/basic/string-util.h

index d210fab672a19e1791c275a31b3257c20098a45e..94cff1853e28d652bf32a026ff83558bd4825fe1 100644 (file)
@@ -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);
index d3b6db9c55decb77943a89f1b0654eb2b9d5b5b3..7cddec712b0ca4cc36930dbd8f8c724c6f7b6039 100644 (file)
@@ -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;
+}
index 52eab27fa3d3ded019458159fdbdd17cd61a0521..f473946864e748054d2a2abf7b9869e24e67661c 100644 (file)
@@ -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);