package: fail on invalid control data

Handle meta data error to produce hard failure.

fixes #10806
cute-signatures
Timo Teräs 2022-01-17 10:55:37 +02:00
parent e8650d4d44
commit a2cd188039
2 changed files with 18 additions and 11 deletions

View File

@ -2398,8 +2398,13 @@ static int apk_db_install_v2meta(struct apk_extract_ctx *ectx, struct apk_istrea
{
struct install_ctx *ctx = container_of(ectx, struct install_ctx, ectx);
apk_blob_t l, token = APK_BLOB_STR("\n");
while (apk_istream_get_delim(is, token, &l) == 0)
read_info_line(ctx, l);
int r;
while (apk_istream_get_delim(is, token, &l) == 0) {
r = read_info_line(ctx, l);
if (r < 0) return r;
}
return 0;
}

View File

@ -568,7 +568,7 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
return 2;
}
if (APK_BLOB_IS_NULL(value))
return -1;
return -APKE_V2PKG_FORMAT;
return 0;
}
@ -644,12 +644,9 @@ static int read_info_line(struct read_info_ctx *ri, apk_blob_t line)
apk_extract_v2_control(&ri->ectx, l, r);
for (i = 0; i < ARRAY_SIZE(fields); i++) {
if (apk_blob_compare(APK_BLOB_STR(fields[i].str), l) == 0) {
apk_pkg_add_info(ri->db, ri->pkg, fields[i].field, r);
return 0;
}
}
for (i = 0; i < ARRAY_SIZE(fields); i++)
if (apk_blob_compare(APK_BLOB_STR(fields[i].str), l) == 0)
return apk_pkg_add_info(ri->db, ri->pkg, fields[i].field, r);
return 0;
}
@ -658,8 +655,13 @@ static int apk_pkg_v2meta(struct apk_extract_ctx *ectx, struct apk_istream *is)
{
struct read_info_ctx *ri = container_of(ectx, struct read_info_ctx, ectx);
apk_blob_t l, token = APK_BLOB_STR("\n");
while (apk_istream_get_delim(is, token, &l) == 0)
read_info_line(ri, l);
int r;
while (apk_istream_get_delim(is, token, &l) == 0) {
r = read_info_line(ri, l);
if (r < 0) return r;
}
return 0;
}