summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2024-07-13 22:06:10 +1000
committerAllan McRae <allan@archlinux.org>2024-07-13 22:06:10 +1000
commitcc0292a1ad0ef4553f06442ec6a2368da9444008 (patch)
treebddbe78b541d227cbbcbd179ed9f1dee831cf5f3
parent16a098a44e42f7d512050245626b80c051eca046 (diff)
Revert "_alpm_archive_fgets(): bail early if reached end of block"
This reverts commit 4dc21b965b891042edc951d53f9ce93bf265cdfd. Causes a segfault when reading some repos (gz compressed?) Fixes #166. Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--lib/libalpm/util.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 63ef6133..5df52657 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -1227,14 +1227,6 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
b->block_offset = b->block;
block_remaining = b->block_size;
- if(block_remaining == 0) {
- /* there was no new data, return what is left; ARCHIVE_EOF will be
- * returned on next call */
- b->line_offset[0] = '\0';
- b->real_line_size = b->line_offset - b->line;
- return ARCHIVE_OK;
- }
-
/* error, cleanup */
if(b->ret < ARCHIVE_OK) {
goto cleanup;
@@ -1290,6 +1282,13 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
memcpy(b->line_offset, b->block_offset, len);
b->line_offset += len;
b->block_offset = b->block + b->block_size;
+ /* there was no new data, return what is left; saved ARCHIVE_EOF will be
+ * returned on next call */
+ if(len == 0) {
+ b->line_offset[0] = '\0';
+ b->real_line_size = b->line_offset - b->line;
+ return ARCHIVE_OK;
+ }
}
}