summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-17 14:06:43 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-17 14:06:43 +0300
commitd694025b91a888996f02a888308fbe9e0a074369 (patch)
tree2db714b2928ce6e8cd67b7b1b0b41128a11a817b
parent3f4f9e9957a27be4efb29498f8fecd63eafcd16c (diff)
downloadapk-tools-d694025b91a888996f02a888308fbe9e0a074369.tar.bz2
apk-tools-d694025b91a888996f02a888308fbe9e0a074369.tar.xz
pkg: fix index generation
that got broke during verify implementation.
-rw-r--r--src/gunzip.c17
-rw-r--r--src/package.c16
2 files changed, 22 insertions, 11 deletions
diff --git a/src/gunzip.c b/src/gunzip.c
index 2c4387e..9c9ea69 100644
--- a/src/gunzip.c
+++ b/src/gunzip.c
@@ -150,26 +150,26 @@ struct apk_gzip_ostream {
struct apk_ostream os;
struct apk_ostream *output;
z_stream zs;
- unsigned char buffer[8*1024];
};
static size_t gzo_write(void *stream, const void *ptr, size_t size)
{
struct apk_gzip_ostream *gos = (struct apk_gzip_ostream *) stream;
+ unsigned char buffer[1024];
size_t have;
int r;
gos->zs.avail_in = size;
gos->zs.next_in = (void *) ptr;
while (gos->zs.avail_in) {
- gos->zs.avail_out = sizeof(gos->buffer);
- gos->zs.next_out = gos->buffer;
+ gos->zs.avail_out = sizeof(buffer);
+ gos->zs.next_out = buffer;
r = deflate(&gos->zs, Z_NO_FLUSH);
if (r == Z_STREAM_ERROR)
return -1;
- have = sizeof(gos->buffer) - gos->zs.avail_out;
+ have = sizeof(buffer) - gos->zs.avail_out;
if (have != 0) {
- r = gos->output->write(gos->output, gos->buffer, have);
+ r = gos->output->write(gos->output, buffer, have);
if (r != have)
return -1;
}
@@ -181,11 +181,14 @@ static size_t gzo_write(void *stream, const void *ptr, size_t size)
static void gzo_close(void *stream)
{
struct apk_gzip_ostream *gos = (struct apk_gzip_ostream *) stream;
+ unsigned char buffer[1024];
size_t have;
+ gos->zs.avail_out = sizeof(buffer);
+ gos->zs.next_out = buffer;
deflate(&gos->zs, Z_FINISH);
- have = sizeof(gos->buffer) - gos->zs.avail_out;
- gos->output->write(gos->output, gos->buffer, have);
+ have = sizeof(buffer) - gos->zs.avail_out;
+ gos->output->write(gos->output, buffer, have);
gos->output->close(gos->output);
deflateEnd(&gos->zs);
diff --git a/src/package.c b/src/package.c
index 04c7c01..3795119 100644
--- a/src/package.c
+++ b/src/package.c
@@ -259,12 +259,15 @@ int apk_script_type(const char *name)
void apk_sign_ctx_init(struct apk_sign_ctx *ctx, int action)
{
memset(ctx, 0, sizeof(struct apk_sign_ctx));
- switch (ctx->action) {
+ ctx->action = action;
+ switch (action) {
case APK_SIGN_VERIFY:
ctx->md = EVP_md_null();
break;
case APK_SIGN_GENERATE_V1:
ctx->md = EVP_md5();
+ ctx->control_started = 1;
+ ctx->data_started = 1;
break;
case APK_SIGN_GENERATE:
default:
@@ -272,7 +275,6 @@ void apk_sign_ctx_init(struct apk_sign_ctx *ctx, int action)
ctx->md = EVP_sha1();
break;
}
- ctx->action = action;
}
@@ -396,7 +398,7 @@ int apk_sign_ctx_mpart_cb(void *ctx, EVP_MD_CTX *mdctx, int part)
memcmp(calculated, sctx->data_checksum,
EVP_MD_CTX_size(mdctx)) == 0)
sctx->data_verified = 1;
- } else {
+ } else if (!sctx->has_data_checksum) {
/* Package identity is checksum of all data */
sctx->identity.type = EVP_MD_CTX_size(mdctx);
EVP_DigestFinal_ex(mdctx, sctx->identity.data, NULL);
@@ -519,7 +521,7 @@ static int read_info_entry(void *ctx, const struct apk_file_info *ae,
if (apk_sign_ctx_process_file(ri->sctx, ae, is) == 0)
return 0;
- if (ri->sctx->data_started == 0 && ae->name[0] == '.') {
+ if (ae->name[0] == '.') {
/* APK 2.0 format */
if (strcmp(ae->name, ".PKGINFO") == 0) {
apk_blob_t blob = apk_blob_from_istream(is, ae->size);
@@ -612,6 +614,9 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file,
if (sctx->action == APK_SIGN_VERIFY && !sctx->data_verified &&
!(apk_flags & APK_FORCE))
goto err;
+ if (sctx->action != APK_SIGN_VERIFY)
+ ctx.pkg->csum = sctx->identity;
+ fprintf(stderr, "%s: %d\n", realfile, ctx.pkg->csum.type);
/* Add implicit busybox dependency if there is scripts */
if (ctx.has_install) {
@@ -809,6 +814,9 @@ int apk_pkg_write_index_entry(struct apk_package *info,
apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->license));
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\n"));
+ if (APK_BLOB_IS_NULL(bbuf))
+ return -1;
+
if (os->write(os, buf, bbuf.ptr - buf) != bbuf.ptr - buf)
return -1;