fix apk_blob_pull_csum to always initialize apk_checksum

Fixes #10686 to not use uninitialized value in the error paths.
cute-signatures
Timo Teräs 2020-05-07 13:28:24 +03:00
parent 5d796b5678
commit 7b76182f39
1 changed files with 6 additions and 9 deletions

View File

@ -468,18 +468,14 @@ void apk_blob_pull_csum(apk_blob_t *b, struct apk_checksum *csum)
{ {
int encoding; int encoding;
if (unlikely(APK_BLOB_IS_NULL(*b))) if (unlikely(APK_BLOB_IS_NULL(*b))) goto fail;
return; if (unlikely(b->len < 2)) goto fail;
if (unlikely(b->len < 2)) {
*b = APK_BLOB_NULL;
return;
}
if (dx(b->ptr[0]) != 0xff) { if (dx(b->ptr[0]) != 0xff) {
/* Assume MD5 for backwards compatibility */ /* Assume MD5 for backwards compatibility */
csum->type = APK_CHECKSUM_MD5; csum->type = APK_CHECKSUM_MD5;
apk_blob_pull_hexdump(b, APK_BLOB_CSUM(*csum)); apk_blob_pull_hexdump(b, APK_BLOB_CSUM(*csum));
if (unlikely(APK_BLOB_IS_NULL(*b))) goto fail;
return; return;
} }
@ -489,8 +485,7 @@ void apk_blob_pull_csum(apk_blob_t *b, struct apk_checksum *csum)
csum->type = APK_CHECKSUM_SHA1; csum->type = APK_CHECKSUM_SHA1;
break; break;
default: default:
*b = APK_BLOB_NULL; goto fail;
return;
} }
b->ptr += 2; b->ptr += 2;
b->len -= 2; b->len -= 2;
@ -503,7 +498,9 @@ void apk_blob_pull_csum(apk_blob_t *b, struct apk_checksum *csum)
apk_blob_pull_base64(b, APK_BLOB_CSUM(*csum)); apk_blob_pull_base64(b, APK_BLOB_CSUM(*csum));
break; break;
default: default:
fail:
*b = APK_BLOB_NULL; *b = APK_BLOB_NULL;
csum->type = APK_CHECKSUM_NONE;
break; break;
} }
} }