summaryrefslogtreecommitdiff
path: root/libarchive/archive_read.c
diff options
context:
space:
mode:
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>2014-09-14 17:23:29 +0900
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>2014-09-14 18:44:50 +0900
commit6c222e59f461bf61962c7de318f946147f58d29b (patch)
tree067a0800e807606f2a48101c3c5013461a401a04 /libarchive/archive_read.c
parentabdce769f16d60e657b47beb3ec855c5d4325bf5 (diff)
downloadlibarchive-6c222e59f461bf61962c7de318f946147f58d29b.tar.gz
Add new APIs that pass passphrases for reading and writing
encrypted archives.
Diffstat (limited to 'libarchive/archive_read.c')
-rw-r--r--libarchive/archive_read.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c
index 0882485f..02bf8d3a 100644
--- a/libarchive/archive_read.c
+++ b/libarchive/archive_read.c
@@ -101,16 +101,17 @@ archive_read_new(void)
{
struct archive_read *a;
- a = (struct archive_read *)malloc(sizeof(*a));
+ a = (struct archive_read *)calloc(1, sizeof(*a));
if (a == NULL)
return (NULL);
- memset(a, 0, sizeof(*a));
a->archive.magic = ARCHIVE_READ_MAGIC;
a->archive.state = ARCHIVE_STATE_NEW;
a->entry = archive_entry_new2(&a->archive);
a->archive.vtable = archive_read_vtable();
+ a->passphrases.last = &a->passphrases.first;
+
return (&a->archive);
}
@@ -1043,6 +1044,7 @@ static int
_archive_read_free(struct archive *_a)
{
struct archive_read *a = (struct archive_read *)_a;
+ struct archive_read_passphrase *p;
int i, n;
int slots;
int r = ARCHIVE_OK;
@@ -1080,6 +1082,18 @@ _archive_read_free(struct archive *_a)
}
}
+ /* Release passphrase list. */
+ p = a->passphrases.first;
+ while (p != NULL) {
+ struct archive_read_passphrase *np = p->next;
+
+ /* A passphrase should be cleaned. */
+ memset(p->passphrase, 0, strlen(p->passphrase));
+ free(p->passphrase);
+ free(p);
+ p = np;
+ }
+
archive_string_free(&a->archive.error_string);
if (a->entry)
archive_entry_free(a->entry);