summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Baranoff <stefan.baranoff@trinitycyber.com>2020-05-19 00:57:14 +0000
committerStefan Baranoff <stefan.baranoff@trinitycyber.com>2020-05-19 01:03:23 +0000
commit35997ddf613702cfef0b026c6a4987dd68918897 (patch)
tree75dac1e46e167400183fcb3bc873b09705d436c7
parent00d2d4be6a6eacb271d5e55c9d5da182a31f87b2 (diff)
downloadlibarchive-35997ddf613702cfef0b026c6a4987dd68918897.tar.gz
Fix memory leak from passphrase callback
There is a bug in the linked list implementation for passphrases. The insert to head function does not account for the tail==head case and causes a leak. The first entry into the list is lost when the second entry is added. The second and beyond entries are are released properly, but the first is lost entirely.
-rw-r--r--libarchive/archive_read_add_passphrase.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/libarchive/archive_read_add_passphrase.c b/libarchive/archive_read_add_passphrase.c
index cf821b5d..f0b1ab93 100644
--- a/libarchive/archive_read_add_passphrase.c
+++ b/libarchive/archive_read_add_passphrase.c
@@ -57,6 +57,10 @@ insert_passphrase_to_head(struct archive_read *a,
{
p->next = a->passphrases.first;
a->passphrases.first = p;
+ if (&a->passphrases.first == a->passphrases.last) {
+ a->passphrases.last = &p->next;
+ p->next = NULL;
+ }
}
static struct archive_read_passphrase *