summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/database.c8
-rw-r--r--src/index.c43
-rw-r--r--src/package.c9
3 files changed, 34 insertions, 26 deletions
diff --git a/src/database.c b/src/database.c
index 61e719d..0b40273 100644
--- a/src/database.c
+++ b/src/database.c
@@ -874,11 +874,11 @@ static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os)
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\n"));
if (os->write(os, buf, bbuf.ptr - buf) != bbuf.ptr - buf)
- return -1;
+ return -EIO;
bbuf = APK_BLOB_BUF(buf);
}
if (os->write(os, buf, bbuf.ptr - buf) != bbuf.ptr - buf)
- return -1;
+ return -EIO;
bbuf = APK_BLOB_BUF(buf);
}
os->write(os, "\n", 1);
@@ -1101,7 +1101,7 @@ static int write_index_entry(apk_hash_item item, void *ctx)
return r;
if (iwctx->os->write(iwctx->os, "\n", 1) != 1)
- return -1;
+ return -EIO;
iwctx->count++;
return 0;
@@ -1124,7 +1124,7 @@ static int apk_db_index_write_nr_cache(struct apk_database *db)
"installed.new",
0644);
if (os == NULL)
- return -1;
+ return -EIO;
ctx.os = os;
list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) {
diff --git a/src/index.c b/src/index.c
index 8d62252..a862d2a 100644
--- a/src/index.c
+++ b/src/index.c
@@ -9,6 +9,7 @@
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
+#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
@@ -61,7 +62,7 @@ static int index_read_file(struct apk_database *db, struct index_ctx *ictx)
if (ictx->index == NULL)
return 0;
if (apk_file_get_info(AT_FDCWD, ictx->index, APK_CHECKSUM_NONE, &fi) < 0)
- return -1;
+ return -EIO;
ictx->index_mtime = fi.mtime;
return apk_db_index_read_file(db, ictx->index, 0);
@@ -185,37 +186,41 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
if (ictx->method == APK_SIGN_GENERATE) {
struct apk_ostream *counter;
- os = apk_ostream_gzip(os);
-
- if (ictx->description != NULL) {
- memset(&fi, 0, sizeof(fi));
- fi.mode = 0644 | S_IFREG;
- fi.name = "DESCRIPTION";
- fi.size = strlen(ictx->description);
- apk_tar_write_entry(os, &fi, ictx->description);
- }
-
memset(&fi, 0, sizeof(fi));
fi.mode = 0644 | S_IFREG;
fi.name = "APKINDEX";
counter = apk_ostream_counter(&fi.size);
- apk_db_index_write(db, counter);
+ r = apk_db_index_write(db, counter);
counter->close(counter);
- apk_tar_write_entry(os, &fi, NULL);
- total = apk_db_index_write(db, os);
- apk_tar_write_padding(os, &fi);
- apk_tar_write_entry(os, NULL, NULL);
+ if (r >= 0) {
+ os = apk_ostream_gzip(os);
+ if (ictx->description != NULL) {
+ struct apk_file_info fi_desc;
+ memset(&fi_desc, 0, sizeof(fi));
+ fi_desc.mode = 0644 | S_IFREG;
+ fi_desc.name = "DESCRIPTION";
+ fi_desc.size = strlen(ictx->description);
+ apk_tar_write_entry(os, &fi_desc, ictx->description);
+ }
+
+ apk_tar_write_entry(os, &fi, NULL);
+ r = apk_db_index_write(db, os);
+ apk_tar_write_padding(os, &fi);
+
+ apk_tar_write_entry(os, NULL, NULL);
+ }
} else {
- total = apk_db_index_write(db, os);
+ r = apk_db_index_write(db, os);
}
os->close(os);
- if (total < 0) {
+ if (r < 0) {
apk_error("Index generation failed: %s", apk_error_str(r));
- return total;
+ return r;
}
+ total = r;
apk_hash_foreach(&db->available.names, warn_if_no_providers, &counts);
if (counts.unsatisfied != 0)
diff --git a/src/package.c b/src/package.c
index 9ad17e9..ecf88c2 100644
--- a/src/package.c
+++ b/src/package.c
@@ -1156,15 +1156,18 @@ int apk_pkg_write_index_entry(struct apk_package *info,
}
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\n"));
- if (APK_BLOB_IS_NULL(bbuf))
- return -1;
+ if (APK_BLOB_IS_NULL(bbuf)) {
+ apk_error("Metadata for package " PKG_VER_FMT " is too long.",
+ PKG_VER_PRINTF(info));
+ return -ENOBUFS;
+ }
bbuf = apk_blob_pushed(APK_BLOB_BUF(buf), bbuf);
if (os->write(os, bbuf.ptr, bbuf.len) != bbuf.len ||
write_depends(os, "D:", info->depends) ||
write_depends(os, "p:", info->provides) ||
write_depends(os, "i:", info->install_if))
- return -1;
+ return -EIO;
return 0;
}