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.
This commit is contained in:
Joerg Behrmann
2023-07-13 11:07:03 +02:00
committed by Luca Boccassi
parent 1dfa58edd3
commit c46f5680ca
3 changed files with 17 additions and 5 deletions

View 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);

View 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;
}

View 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);