version: increase number of digits supported in version component

Report also version numbers as invalid if there's more than 18
digits.

fixes #10774
cute-signatures
Timo Teräs 2021-10-25 13:29:41 +03:00
parent d38e2dd65a
commit 50ab589e9a
3 changed files with 8 additions and 3 deletions

View File

@ -68,11 +68,12 @@ static void next_token(int *type, apk_blob_t *blob)
*type = n; *type = n;
} }
static int get_token(int *type, apk_blob_t *blob) static int64_t get_token(int *type, apk_blob_t *blob)
{ {
static const char *pre_suffixes[] = { "alpha", "beta", "pre", "rc" }; static const char *pre_suffixes[] = { "alpha", "beta", "pre", "rc" };
static const char *post_suffixes[] = { "cvs", "svn", "git", "hg", "p" }; static const char *post_suffixes[] = { "cvs", "svn", "git", "hg", "p" };
int v = 0, i = 0, nt = TOKEN_INVALID; int i = 0, nt = TOKEN_INVALID;
int64_t v = 0;
if (blob->len <= 0) { if (blob->len <= 0) {
*type = TOKEN_END; *type = TOKEN_END;
@ -96,6 +97,7 @@ static int get_token(int *type, apk_blob_t *blob)
v *= 10; v *= 10;
v += blob->ptr[i++] - '0'; v += blob->ptr[i++] - '0';
} }
if (i >= 18) goto invalid;
break; break;
case TOKEN_LETTER: case TOKEN_LETTER:
v = blob->ptr[i++]; v = blob->ptr[i++];
@ -121,6 +123,7 @@ static int get_token(int *type, apk_blob_t *blob)
break; break;
/* fallthrough: invalid suffix */ /* fallthrough: invalid suffix */
default: default:
invalid:
*type = TOKEN_INVALID; *type = TOKEN_INVALID;
return -1; return -1;
} }
@ -200,7 +203,7 @@ int apk_version_validate(apk_blob_t ver)
int apk_version_compare_blob_fuzzy(apk_blob_t a, apk_blob_t b, int fuzzy) int apk_version_compare_blob_fuzzy(apk_blob_t a, apk_blob_t b, int fuzzy)
{ {
int at = TOKEN_DIGIT, bt = TOKEN_DIGIT, tt; int at = TOKEN_DIGIT, bt = TOKEN_DIGIT, tt;
int av = 0, bv = 0; int64_t av = 0, bv = 0;
if (APK_BLOB_IS_NULL(a) || APK_BLOB_IS_NULL(b)) { if (APK_BLOB_IS_NULL(a) || APK_BLOB_IS_NULL(b)) {
if (APK_BLOB_IS_NULL(a) && APK_BLOB_IS_NULL(b)) if (APK_BLOB_IS_NULL(a) && APK_BLOB_IS_NULL(b))

View File

@ -726,3 +726,4 @@
1.3_pre1-r1 < 1.3.2 1.3_pre1-r1 < 1.3.2
1.0_p10-r0 > 1.0_p9-r0 1.0_p10-r0 > 1.0_p9-r0
0.1.0_alpha_pre2 < 0.1.0_alpha 0.1.0_alpha_pre2 < 0.1.0_alpha
1.0.0_pre20191002222144-r0 < 1.0.0_pre20210530193627-r0

View File

@ -726,3 +726,4 @@
1.3_pre1-r1 < 1.3.2 1.3_pre1-r1 < 1.3.2
1.0_p10-r0 > 1.0_p9-r0 1.0_p10-r0 > 1.0_p9-r0
0.1.0_alpha_pre2 < 0.1.0_alpha 0.1.0_alpha_pre2 < 0.1.0_alpha
1.0.0_pre20191002222144-r0 < 1.0.0_pre20210530193627-r0