From: Arran Cudbard-Bell Date: Tue, 8 Dec 2020 23:13:29 +0000 (-0700) Subject: Simplify version comparison function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3f8d49b71628525c2fc060c9b31cf849f82defd;p=thirdparty%2Ffreeradius-server.git Simplify version comparison function --- diff --git a/src/build/version.c b/src/build/version.c index ab40220c5a9..ade4cff8b72 100644 --- a/src/build/version.c +++ b/src/build/version.c @@ -81,7 +81,6 @@ static int make_version_cmp(bool *err, while ((a < a_end) && (b < b_end)) { unsigned long a_num, b_num; - char buff[20]; size_t a_len, b_len; int ret; bool a_str = false; @@ -89,35 +88,24 @@ static int make_version_cmp(bool *err, a_num = strtoul(a, &a_q, 10); if (a == a_q) { FIND_SEP(a_q, a); - a_len = a_q - a; - if (a_len >= sizeof(buff)) { - ERROR("Version component too long \"%s\"", a); - error: - *err = true; - return 0; - } - - strncpy(buff, a_q, a_len); - a_str = true; } b_num = strtoul(a, &b_q, 10); + /* + * A and B are both strings + */ if (b == b_q) { if (!a_str) { - str_v_num: - ERROR("Can't compare string version component to numeric component"); - goto error; + ERROR("Can't compare string component to numeric component"); + error: + *err = true; + return 0; } FIND_SEP(b_q, b); - b_len = b_q - b; - if (b_len >= sizeof(buff)) { - ERROR("Version component too long \"%s\"", b); - goto error; - } if (a_len != b_len) { ERROR("Version component length doesn't match " @@ -135,21 +123,33 @@ static int make_version_cmp(bool *err, a = a_q; b = b_q; - - if (IS_SEP(*a)) a++; - if (IS_SEP(*b)) b++; - - continue; - } else if (a_str) goto str_v_num; + /* + * A was a number but B was a string. + */ + } else if (a_str) { + ERROR("Can't compare numeric component to string component"); + goto error; /* - * Compare the numeric version component + * A and B are both numbers. */ - ret = (a_num > b_num) - (a_num < b_num); - if (ret != 0) return ret; + } else { + ret = (a_num > b_num) - (a_num < b_num); + if (ret != 0) return ret; + } + + if (!IS_SEP(*a)) { + ERROR("Missing version component separator \"%s\"", a); + goto error; + } + + if (!IS_SEP(*b)) { + ERROR("Missing version component separator \"%s\"", b); + goto error; + } - if (IS_SEP(*a)) a++; - if (IS_SEP(*b)) b++; + a++; + b++; } if ((a < a_end) || (b < b_end)) {