summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/be_package.c10
-rw-r--r--lib/libalpm/be_sync.c22
-rw-r--r--lib/libalpm/util.c7
3 files changed, 28 insertions, 11 deletions
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index c70d1e9a..c89365a2 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -137,13 +137,13 @@ static struct pkg_operations *get_file_pkg_ops(void)
* @param archive the archive to read from, pointed at the .PKGINFO entry
* @param newpkg an empty pmpkg_t struct to fill with package info
*
- * @return 0 on success, 1 on error
+ * @return 0 on success, -1 on error
*/
static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
{
char *ptr = NULL;
char *key = NULL;
- int linenum = 0;
+ int ret, linenum = 0;
struct archive_read_buffer buf;
memset(&buf, 0, sizeof(buf));
@@ -151,7 +151,7 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
buf.max_line_size = 512 * 1024;
/* loop until we reach EOF or other error */
- while(_alpm_archive_fgets(a, &buf) == ARCHIVE_OK) {
+ while((ret = _alpm_archive_fgets(a, &buf)) == ARCHIVE_OK) {
char *line = _alpm_strtrim(buf.line);
linenum++;
@@ -215,6 +215,10 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
}
line[0] = '\0';
}
+ if(ret != ARCHIVE_EOF) {
+ _alpm_log(PM_LOG_DEBUG, "error parsing package descfile\n");
+ return -1;
+ }
return 0;
}
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 953e4dc1..aeba86f1 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -294,6 +294,7 @@ static int sync_db_populate(pmdb_t *db)
_alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
name);
_alpm_pkg_free(pkg);
+ pkg = NULL;
continue;
}
@@ -301,6 +302,7 @@ static int sync_db_populate(pmdb_t *db)
if(_alpm_pkghash_find(db->pkgcache, pkg->name)) {
_alpm_log(PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name);
_alpm_pkg_free(pkg);
+ pkg = NULL;
continue;
}
@@ -316,7 +318,14 @@ static int sync_db_populate(pmdb_t *db)
count++;
} else {
/* we have desc, depends or deltas - parse it */
- sync_db_read(db, archive, entry, pkg);
+ if(sync_db_read(db, archive, entry, pkg) != 0) {
+ _alpm_log(PM_LOG_ERROR,
+ _("could not parse package '%s' description file from db '%s'\n"),
+ pkg->name, db->treename);
+ _alpm_pkg_free(pkg);
+ pkg = NULL;
+ continue;
+ }
}
}
@@ -401,7 +410,8 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
if(strcmp(filename, "desc") == 0 || strcmp(filename, "depends") == 0
|| strcmp(filename, "deltas") == 0) {
- while(_alpm_archive_fgets(archive, &buf) == ARCHIVE_OK) {
+ int ret;
+ while((ret = _alpm_archive_fgets(archive, &buf)) == ARCHIVE_OK) {
char *line = _alpm_strtrim(buf.line);
if(strcmp(line, "%NAME%") == 0) {
@@ -478,6 +488,9 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
}
}
}
+ if(ret != ARCHIVE_EOF) {
+ goto error;
+ }
} else if(strcmp(filename, "files") == 0) {
/* currently do nothing with this file */
} else {
@@ -485,10 +498,11 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
_alpm_log(PM_LOG_DEBUG, "unknown database file: %s\n", filename);
}
+ return 0;
+
error:
FREE(pkgname);
- /* TODO: return 0 always? */
- return 0;
+ return -1;
}
static int sync_db_version(pmdb_t UNUSED *db)
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index e25e19d3..5821bf9f 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -771,20 +771,19 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
/* allocate our buffer, or ensure our existing one is big enough */
if(!b->line) {
/* set the initial buffer to the read block_size */
- CALLOC(b->line, b->block_size + 1, sizeof(char),
- RET_ERR(PM_ERR_MEMORY, -1));
+ CALLOC(b->line, b->block_size + 1, sizeof(char), return ENOMEM);
b->line_size = b->block_size + 1;
b->line_offset = b->line;
} else {
size_t needed = (size_t)((b->line_offset - b->line)
+ (i - b->block_offset) + 1);
if(needed > b->max_line_size) {
- RET_ERR(PM_ERR_MEMORY, -1);
+ return ERANGE;
}
if(needed > b->line_size) {
/* need to realloc + copy data to fit total length */
char *new;
- CALLOC(new, needed, sizeof(char), RET_ERR(PM_ERR_MEMORY, -1));
+ CALLOC(new, needed, sizeof(char), return ENOMEM);
memcpy(new, b->line, b->line_size);
b->line_size = needed;
b->line_offset = new + (b->line_offset - b->line);