From: Adrian Vovk Date: Sat, 22 Jun 2024 00:03:12 +0000 (-0400) Subject: sysupdate: Fix resource_find_instance X-Git-Tag: v257-rc1~616^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79348036342e80eefd59e9828c664b95c19319bc;p=thirdparty%2Fsystemd.git sysupdate: Fix resource_find_instance The current implementation will never find a match, because in the event of a match instance_cmp falls through to comparing paths and the key we're matching against will always have a path of NULL. So let's just use a separate compare function, just to make sure future updates to instance_cmp don't break resource_find_instance again. --- diff --git a/src/sysupdate/sysupdate-resource.c b/src/sysupdate/sysupdate-resource.c index 5b7aee2b54c..94308998971 100644 --- a/src/sysupdate/sysupdate-resource.c +++ b/src/sysupdate/sysupdate-resource.c @@ -527,13 +527,25 @@ int resource_load_instances(Resource *rr, bool verify, Hashmap **web_cache) { return 0; } +static int instance_version_match(Instance *const*a, Instance *const*b) { + assert(a); + assert(b); + assert(*a); + assert(*b); + assert((*a)->metadata.version); + assert((*b)->metadata.version); + + /* List is sorted newest-to-oldest */ + return -strverscmp_improved((*a)->metadata.version, (*b)->metadata.version); +} + Instance* resource_find_instance(Resource *rr, const char *version) { Instance key = { .metadata.version = (char*) version, }, *k = &key; Instance **found; - found = typesafe_bsearch(&k, rr->instances, rr->n_instances, instance_cmp); + found = typesafe_bsearch(&k, rr->instances, rr->n_instances, instance_version_match); if (!found) return NULL;