From: Lennart Poettering Date: Fri, 2 Jun 2023 10:25:09 +0000 (+0200) Subject: dissect-image: fix partition label version compare X-Git-Tag: v254-rc1~302 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ca6cdd26055d6cf740662ed9102d674c7bf3d859;p=thirdparty%2Fsystemd.git dissect-image: fix partition label version compare The logic was borked: if we find multiple partitions of the same designator, we should first prefer the better arch, and then prefer the better version, and then the first found. Fix that. Fixes: #27897 --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index becd13f4c5c..cf432e2177a 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1217,16 +1217,19 @@ static int dissect_image( } if (m->partitions[type.designator].found) { + int c; + /* For most partition types the first one we see wins. Except for the * rootfs and /usr, where we do a version compare of the label, and * let the newest version win. This permits a simple A/B versioning * scheme in OS images. */ - if (compare_arch(type.arch, m->partitions[type.designator].architecture) <= 0) + c = compare_arch(type.arch, m->partitions[type.designator].architecture); + if (c < 0) /* the arch we already found is better than the one we found now */ continue; - - if (!partition_designator_is_versioned(type.designator) || - strverscmp_improved(m->partitions[type.designator].label, label) >= 0) + if (c == 0 && /* same arch? then go by version in label */ + (!partition_designator_is_versioned(type.designator) || + strverscmp_improved(label, m->partitions[type.designator].label) <= 0)) continue; dissected_partition_done(m->partitions + type.designator);