summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid Rankin <reidrankin@gmail.com>2020-01-24 15:13:43 +0000
committerTimo Teräs <timo.teras@iki.fi>2020-01-25 16:35:31 +0200
commitc7c8ab7c574d9c4360daf41bc0a7e6ac78da0f32 (patch)
treebb94450c834758b00517248cdf7d7ca798ab3194
parentaa882df5116df56d95b3750c28fab5013b680c7a (diff)
downloadapk-tools-c7c8ab7c574d9c4360daf41bc0a7e6ac78da0f32.tar.gz
apk-tools-c7c8ab7c574d9c4360daf41bc0a7e6ac78da0f32.tar.bz2
apk-tools-c7c8ab7c574d9c4360daf41bc0a7e6ac78da0f32.tar.xz
apk-tools-c7c8ab7c574d9c4360daf41bc0a7e6ac78da0f32.zip
don't use hardcoded checksum buffer sizes
-rw-r--r--src/apk_blob.h9
-rw-r--r--src/manifest.c4
2 files changed, 8 insertions, 5 deletions
diff --git a/src/apk_blob.h b/src/apk_blob.h
index c14980d..91ba9b3 100644
--- a/src/apk_blob.h
+++ b/src/apk_blob.h
@@ -36,12 +36,15 @@ extern apk_blob_t apk_null_blob;
#define APK_CHECKSUM_MD5 16
#define APK_CHECKSUM_SHA1 20
#define APK_CHECKSUM_DEFAULT APK_CHECKSUM_SHA1
+#define APK_CHECKSUM_MAX APK_CHECKSUM_SHA1
-#define APK_BLOB_CHECKSUM_BUF 34
+/* Enough space for a hexdump of the longest checksum possible plus
+ * a two-character type prefix */
+#define APK_BLOB_CHECKSUM_BUF (2 + (2 * APK_CHECKSUM_MAX))
-/* Internal cointainer for MD5 or SHA1 */
+/* Internal container for checksums */
struct apk_checksum {
- unsigned char data[20];
+ unsigned char data[APK_CHECKSUM_MAX];
unsigned char type;
};
diff --git a/src/manifest.c b/src/manifest.c
index 145714c..8a6d9e8 100644
--- a/src/manifest.c
+++ b/src/manifest.c
@@ -36,7 +36,7 @@ static void process_package(struct apk_database *db, struct apk_package *pkg)
struct apk_db_dir_instance *diri;
struct apk_db_file *file;
struct hlist_node *dc, *dn, *fc, *fn;
- char csum_buf[(APK_CHECKSUM_SHA1 * 2) + 1];
+ char csum_buf[APK_BLOB_CHECKSUM_BUF];
if (ipkg == NULL)
return;
@@ -62,7 +62,7 @@ static int read_file_entry(void *ctx, const struct apk_file_info *ae,
struct apk_istream *is)
{
struct manifest_file_ctx *mctx = ctx;
- char csum_buf[(APK_CHECKSUM_SHA1 * 2) + 1];
+ char csum_buf[APK_BLOB_CHECKSUM_BUF];
apk_blob_t csum_blob = APK_BLOB_BUF(csum_buf);
int r;