mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-20 10:12:15 +01:00
Change rule from "reject non-recommended versions" to "reject obsolete versions". A version is "obsolete" if it is non-recommended, and at least one recommended version is newer than it.
svn:r2052
This commit is contained in:
parent
1040762531
commit
df3544422c
@ -221,25 +221,58 @@ get_recommended_software_from_directory(const char *str)
|
||||
#undef REC
|
||||
}
|
||||
|
||||
/** Return 1 if myversion is in versionlist. Else return 0.
|
||||
* (versionlist is a comma-separated list of versions.) */
|
||||
/* static */ int is_recommended_version(const char *myversion,
|
||||
/** Return 1 if <b>myversion</b> is not in <b>versionlist</b>, and if at least
|
||||
* one version of Tor on <b>versionlist</b> is newer than <b>myversion</b>.
|
||||
* Otherwise return 0.
|
||||
* (versionlist is a comma-separated list of version strings,
|
||||
* optionally prefixed with "Tor". Versions that can't be parsed are
|
||||
* ignored.) */
|
||||
/* static */ int is_obsolete_version(const char *myversion,
|
||||
const char *versionlist) {
|
||||
int len_myversion = strlen(myversion);
|
||||
char *comma;
|
||||
const char *end = versionlist + strlen(versionlist);
|
||||
char *version, *comma, *cp;
|
||||
tor_version_t mine, other;
|
||||
int found_newer = 0, r;
|
||||
|
||||
log_fn(LOG_DEBUG,"checking '%s' in '%s'.", myversion, versionlist);
|
||||
|
||||
if (tor_version_parse(myversion, &mine)) {
|
||||
log_fn(LOG_ERR, "I couldn't parse my own version (%s)", myversion);
|
||||
tor_assert(0);
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
comma = strchr(versionlist, ',');
|
||||
if( ((comma ? comma : end) - versionlist == len_myversion) &&
|
||||
!strncmp(versionlist, myversion, len_myversion))
|
||||
/* only do strncmp if the length matches */
|
||||
return 1; /* success, it's there */
|
||||
if(!comma)
|
||||
return 0; /* nope */
|
||||
versionlist = comma+1;
|
||||
version = tor_strndup(versionlist,
|
||||
comma?(comma-versionlist):strlen(versionlist));
|
||||
cp = version;
|
||||
while (isspace(*cp))
|
||||
++cp;
|
||||
if (!strncmp(cp, "Tor ", 4))
|
||||
cp += 4;
|
||||
|
||||
if (tor_version_parse(cp, &other)) {
|
||||
/* Couldn't parse other; it can't be a match. */
|
||||
} else {
|
||||
r = tor_version_compare(&mine, &other);
|
||||
if (r==0) {
|
||||
tor_free(version);
|
||||
return 0; /* It's a match. */
|
||||
} else if (r<0) {
|
||||
found_newer = 1;
|
||||
}
|
||||
}
|
||||
tor_free(version);
|
||||
if (comma)
|
||||
versionlist = comma+1;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (!found_newer) {
|
||||
log_fn(LOG_WARN, "This version of Tor (%s) is newer than any on the recommended list (%s)",
|
||||
myversion, versionlist);
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,11 +287,7 @@ int check_software_version_against_directory(const char *directory,
|
||||
log_fn(LOG_WARN, "No recommended-versions string found in directory");
|
||||
return -1;
|
||||
}
|
||||
/* Look for versions of the form "0.1.0" and of the form "Tor 0.1.0".
|
||||
* Eventually, we should deprecate the first form.
|
||||
*/
|
||||
if (is_recommended_version(VERSION, v) ||
|
||||
is_recommended_version("Tor "VERSION, v)) {
|
||||
if (!is_obsolete_version(VERSION, v)) {
|
||||
tor_free(v);
|
||||
return 0;
|
||||
}
|
||||
@ -1377,30 +1406,6 @@ int tor_version_compare(tor_version_t *a, tor_version_t *b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static tor_version_t *my_tor_version=NULL;
|
||||
|
||||
/** 1 for unequal, newer or can't tell; 0 for equal, -1 for older. */
|
||||
int tor_version_compare_to_mine(const char *s)
|
||||
{
|
||||
tor_version_t v;
|
||||
|
||||
if (!my_tor_version) {
|
||||
my_tor_version = tor_malloc(sizeof(tor_version_t));
|
||||
if (tor_version_parse(VERSION, my_tor_version)) {
|
||||
log_fn(LOG_ERR, "I couldn't parse my own version ("VERSION")");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (tor_version_parse(s,&v)) {
|
||||
log_fn(LOG_WARN, "Unparseable tor version %s", s);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return tor_version_compare(my_tor_version, &v);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
mode:c
|
||||
|
@ -647,7 +647,7 @@ test_onion_handshake() {
|
||||
}
|
||||
|
||||
/* from routerparse.c */
|
||||
int is_recommended_version(const char *myversion, const char *start);
|
||||
int is_obsolete_version(const char *myversion, const char *start);
|
||||
|
||||
void
|
||||
test_dir_format()
|
||||
@ -816,16 +816,6 @@ test_dir_format()
|
||||
tor_free(dir1); /* XXXX And more !*/
|
||||
tor_free(dir2); /* And more !*/
|
||||
|
||||
/* make sure is_recommended_version() works */
|
||||
test_eq(1, is_recommended_version("abc", "abc"));
|
||||
test_eq(1, is_recommended_version("abc", "ab,abd,abde,abc,abcde"));
|
||||
test_eq(1, is_recommended_version("abc", "ab,abd,abde,abcde,abc"));
|
||||
test_eq(1, is_recommended_version("abc", "abc,abd,abde,abc,abcde"));
|
||||
test_eq(1, is_recommended_version("a", "a,ab,abd,abde,abc,abcde"));
|
||||
test_eq(0, is_recommended_version("a", "ab,abd,abde,abc,abcde"));
|
||||
test_eq(0, is_recommended_version("abb", "ab,abd,abde,abc,abcde"));
|
||||
test_eq(0, is_recommended_version("a", ""));
|
||||
|
||||
/* Try out version parsing functionality */
|
||||
test_eq(0, tor_version_parse("0.3.4pre2-cvs", &ver1));
|
||||
test_eq(0, ver1.major);
|
||||
@ -855,6 +845,16 @@ test_dir_format()
|
||||
test_eq(VER_RELEASE, ver1.status);
|
||||
test_eq(999, ver1.patchlevel);
|
||||
test_eq(IS_NOT_CVS, ver1.cvs);
|
||||
|
||||
/* make sure is_obsolete_version() works */
|
||||
test_eq(1, is_obsolete_version("0.0.1", "Tor 0.0.2"));
|
||||
test_eq(1, is_obsolete_version("0.0.1", "0.0.2, Tor 0.0.3"));
|
||||
test_eq(1, is_obsolete_version("0.0.1", "0.0.2,Tor 0.0.3"));
|
||||
test_eq(1, is_obsolete_version("0.0.1", "0.0.3,BetterTor 0.0.1"));
|
||||
test_eq(0, is_obsolete_version("0.0.2", "Tor 0.0.2,Tor 0.0.3"));
|
||||
test_eq(1, is_obsolete_version("0.0.2", "Tor 0.0.2pre1,Tor 0.0.3"));
|
||||
test_eq(0, is_obsolete_version("0.1.0", "Tor 0.0.2,Tor 0.0.3"));
|
||||
test_eq(0, is_obsolete_version("0.0.7rc2", "0.0.7,Tor 0.0.7rc2,Tor 0.0.8"));
|
||||
}
|
||||
|
||||
void test_rend_fns()
|
||||
|
Loading…
Reference in New Issue
Block a user