From a2cd188039231e1cb8d218e75970900bb4a9ae22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Mon, 17 Jan 2022 10:55:37 +0200 Subject: [PATCH] package: fail on invalid control data Handle meta data error to produce hard failure. fixes #10806 --- src/database.c | 9 +++++++-- src/package.c | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/database.c b/src/database.c index f5d3f0f..6b48bb8 100644 --- a/src/database.c +++ b/src/database.c @@ -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; } diff --git a/src/package.c b/src/package.c index cd00f18..eef5dd5 100644 --- a/src/package.c +++ b/src/package.c @@ -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; }