diff options
author | Timo Teräs <timo.teras@iki.fi> | 2022-01-17 10:55:37 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2022-01-17 10:55:37 +0200 |
commit | a2cd188039231e1cb8d218e75970900bb4a9ae22 (patch) | |
tree | 548763379211b5d7e09739becc8bb195f52b9df9 /src | |
parent | e8650d4d44d32a3a605283d921e535fff3a17089 (diff) | |
download | apk-tools-a2cd188039231e1cb8d218e75970900bb4a9ae22.tar.gz apk-tools-a2cd188039231e1cb8d218e75970900bb4a9ae22.tar.bz2 apk-tools-a2cd188039231e1cb8d218e75970900bb4a9ae22.tar.xz apk-tools-a2cd188039231e1cb8d218e75970900bb4a9ae22.zip |
package: fail on invalid control data
Handle meta data error to produce hard failure.
fixes #10806
Diffstat (limited to 'src')
-rw-r--r-- | src/database.c | 9 | ||||
-rw-r--r-- | 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; } |