adb: fix some error handling paths

cute-signatures
Timo Teräs 2021-07-26 14:10:58 +03:00
parent 083ea5a13b
commit 003e713502
3 changed files with 9 additions and 9 deletions

View File

@ -97,11 +97,11 @@ static int __adb_m_parse(struct adb *db, apk_blob_t data, struct apk_trust *t,
allowed = BIT(ADB_BLOCK_SIG) | BIT(ADB_BLOCK_DATA) | BIT(ADB_BLOCK_DATAX); allowed = BIT(ADB_BLOCK_SIG) | BIT(ADB_BLOCK_DATA) | BIT(ADB_BLOCK_DATAX);
if (b.len < 16) { if (b.len < 16) {
r = -APKE_ADB_BLOCK; r = -APKE_ADB_BLOCK;
break; goto err;
} }
if (((struct adb_hdr*)b.ptr)->adb_compat_ver != 0) { if (((struct adb_hdr*)b.ptr)->adb_compat_ver != 0) {
r = -APKE_ADB_VERSION; r = -APKE_ADB_VERSION;
break; goto err;
} }
db->adb = b; db->adb = b;
break; break;
@ -116,7 +116,7 @@ static int __adb_m_parse(struct adb *db, apk_blob_t data, struct apk_trust *t,
break; break;
case ADB_BLOCK_DATAX: case ADB_BLOCK_DATAX:
r = -APKE_ADB_BLOCK; r = -APKE_ADB_BLOCK;
break; goto err;
} }
r = cb(db, blk, apk_istream_from_blob(&is, b)); r = cb(db, blk, apk_istream_from_blob(&is, b));
if (r < 0) break; if (r < 0) break;
@ -206,12 +206,12 @@ static int __adb_m_stream(struct adb *db, struct apk_istream *is, uint32_t expec
db->adb.len = adb_block_length(&blk); db->adb.len = adb_block_length(&blk);
if (db->adb.len < 16) { if (db->adb.len < 16) {
r = -APKE_ADB_BLOCK; r = -APKE_ADB_BLOCK;
break; goto err;
} }
if ((r = apk_istream_read(is, db->adb.ptr, sz)) < 0) goto err; if ((r = apk_istream_read(is, db->adb.ptr, sz)) < 0) goto err;
if (((struct adb_hdr*)db->adb.ptr)->adb_compat_ver != 0) { if (((struct adb_hdr*)db->adb.ptr)->adb_compat_ver != 0) {
r = -APKE_ADB_VERSION; r = -APKE_ADB_VERSION;
break; goto err;
} }
r = cb(db, &blk, apk_istream_from_blob(&seg.is, db->adb)); r = cb(db, &blk, apk_istream_from_blob(&seg.is, db->adb));
if (r < 0) goto err; if (r < 0) goto err;
@ -232,7 +232,7 @@ static int __adb_m_stream(struct adb *db, struct apk_istream *is, uint32_t expec
break; break;
case ADB_BLOCK_DATAX: case ADB_BLOCK_DATAX:
r = -APKE_ADB_BLOCK; r = -APKE_ADB_BLOCK;
break; goto err;
} }
apk_istream_segment(&seg, is, sz, 0); apk_istream_segment(&seg, is, sz, 0);
@ -456,7 +456,7 @@ struct adb_obj *adb_ro_obj(const struct adb_obj *o, unsigned i, struct adb_obj *
schema = container_of(o->schema->fields[0].kind, struct adb_object_schema, kind); schema = container_of(o->schema->fields[0].kind, struct adb_object_schema, kind);
else if (i > 0 && i < o->schema->num_fields) else if (i > 0 && i < o->schema->num_fields)
schema = container_of(o->schema->fields[i-1].kind, struct adb_object_schema, kind); schema = container_of(o->schema->fields[i-1].kind, struct adb_object_schema, kind);
assert(schema->kind == ADB_KIND_OBJECT || schema->kind == ADB_KIND_ARRAY); assert(schema && (schema->kind == ADB_KIND_OBJECT || schema->kind == ADB_KIND_ARRAY));
} }
return adb_r_obj(o->db, adb_ro_val(o, i), no, schema); return adb_r_obj(o->db, adb_ro_val(o, i), no, schema);

View File

@ -341,7 +341,7 @@ static int extract_main(void *pctx, struct apk_ctx *ac, struct apk_string_array
struct extract_ctx *ctx = pctx; struct extract_ctx *ctx = pctx;
struct apk_out *out = &ac->out; struct apk_out *out = &ac->out;
char **parg; char **parg;
int r; int r = 0;
ctx->ac = ac; ctx->ac = ac;
ctx->extract_flags |= APK_EXTRACTF_NO_OVERWRITE; ctx->extract_flags |= APK_EXTRACTF_NO_OVERWRITE;

View File

@ -174,7 +174,7 @@ int apk_istream_get_max(struct apk_istream *is, size_t max, apk_blob_t *data)
int apk_istream_get_delim(struct apk_istream *is, apk_blob_t token, apk_blob_t *data) int apk_istream_get_delim(struct apk_istream *is, apk_blob_t token, apk_blob_t *data)
{ {
apk_blob_t ret = APK_BLOB_NULL, left = APK_BLOB_NULL; apk_blob_t ret = APK_BLOB_NULL, left = APK_BLOB_NULL;
int r; int r = 0;
do { do {
if (apk_blob_split(APK_BLOB_PTR_LEN((char*)is->ptr, is->end - is->ptr), token, &ret, &left)) if (apk_blob_split(APK_BLOB_PTR_LEN((char*)is->ptr, is->end - is->ptr), token, &ret, &left))