adb: fix handling of conflicts

Ensure not to mask away previously set APK_VERSION_CONFLICT when
serializing.

When deserializing, make sure to actually write out the conflict
flag when no version part is set.

When creating apk_dependency, ensure to set the conflict bit
correctly and mask it off result_mask.

Fixes https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10824
cute-signatures
Daniel Kolesa 2022-03-06 19:08:06 +01:00 committed by Timo Teräs
parent fa913aba4b
commit c5d9aaa1ee
3 changed files with 15 additions and 7 deletions

View File

@ -4,8 +4,6 @@
#include "apk_print.h" #include "apk_print.h"
#include "apk_version.h" #include "apk_version.h"
#define APK_VERSION_CONFLICT 16
/* Few helpers to map old database to new one */ /* Few helpers to map old database to new one */
int apk_dep_split(apk_blob_t *b, apk_blob_t *bdep) int apk_dep_split(apk_blob_t *b, apk_blob_t *bdep)
@ -259,10 +257,17 @@ static apk_blob_t dependency_tostring(struct adb_obj *obj, char *buf, size_t buf
name = adb_ro_blob(obj, ADBI_DEP_NAME); name = adb_ro_blob(obj, ADBI_DEP_NAME);
ver = adb_ro_blob(obj, ADBI_DEP_VERSION); ver = adb_ro_blob(obj, ADBI_DEP_VERSION);
if (APK_BLOB_IS_NULL(name)) return APK_BLOB_NULL;
if (APK_BLOB_IS_NULL(ver)) return name;
mask = adb_ro_int(obj, ADBI_DEP_MATCH) ?: APK_VERSION_EQUAL; mask = adb_ro_int(obj, ADBI_DEP_MATCH) ?: APK_VERSION_EQUAL;
if (APK_BLOB_IS_NULL(name)) return APK_BLOB_NULL;
if (APK_BLOB_IS_NULL(ver)) {
if (mask & APK_VERSION_CONFLICT)
return APK_BLOB_PTR_LEN(buf,
snprintf(buf, bufsz, "!"BLOB_FMT,
BLOB_PRINTF(name)));
return name;
}
return APK_BLOB_PTR_LEN(buf, return APK_BLOB_PTR_LEN(buf,
snprintf(buf, bufsz, "%s"BLOB_FMT"%s"BLOB_FMT, snprintf(buf, bufsz, "%s"BLOB_FMT"%s"BLOB_FMT,
(mask & APK_VERSION_CONFLICT) ? "!" : "", (mask & APK_VERSION_CONFLICT) ? "!" : "",
@ -295,7 +300,7 @@ static int dependency_fromstring(struct adb_obj *obj, apk_blob_t bdep)
if (!apk_blob_spn(bop, apk_spn_dependency_comparer, &bop, &bver)) if (!apk_blob_spn(bop, apk_spn_dependency_comparer, &bop, &bver))
goto fail; goto fail;
mask = 0; mask &= APK_VERSION_CONFLICT;
for (i = 0; i < bop.len; i++) { for (i = 0; i < bop.len; i++) {
switch (bop.ptr[i]) { switch (bop.ptr[i]) {
case '<': case '<':

View File

@ -17,6 +17,7 @@
#define APK_VERSION_LESS 2 #define APK_VERSION_LESS 2
#define APK_VERSION_GREATER 4 #define APK_VERSION_GREATER 4
#define APK_VERSION_FUZZY 8 #define APK_VERSION_FUZZY 8
#define APK_VERSION_CONFLICT 16
#define APK_DEPMASK_ANY (APK_VERSION_EQUAL|APK_VERSION_LESS|\ #define APK_DEPMASK_ANY (APK_VERSION_EQUAL|APK_VERSION_LESS|\
APK_VERSION_GREATER|APK_VERSION_FUZZY) APK_VERSION_GREATER|APK_VERSION_FUZZY)

View File

@ -457,10 +457,12 @@ int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps, s
void apk_dep_from_adb(struct apk_dependency *dep, struct apk_database *db, struct adb_obj *d) void apk_dep_from_adb(struct apk_dependency *dep, struct apk_database *db, struct adb_obj *d)
{ {
int mask = adb_ro_int(d, ADBI_DEP_MATCH);
*dep = (struct apk_dependency) { *dep = (struct apk_dependency) {
.name = apk_db_get_name(db, adb_ro_blob(d, ADBI_DEP_NAME)), .name = apk_db_get_name(db, adb_ro_blob(d, ADBI_DEP_NAME)),
.version = apk_atomize_dup(&db->atoms, adb_ro_blob(d, ADBI_DEP_VERSION)), .version = apk_atomize_dup(&db->atoms, adb_ro_blob(d, ADBI_DEP_VERSION)),
.result_mask = adb_ro_int(d, ADBI_DEP_MATCH) ?: APK_VERSION_EQUAL, .conflict = !!(mask & APK_VERSION_CONFLICT),
.result_mask = (mask & ~APK_VERSION_CONFLICT) ?: APK_VERSION_EQUAL,
}; };
} }