]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix memory leak from passphrase callback 1378/head
authorStefan Baranoff <stefan.baranoff@trinitycyber.com>
Tue, 19 May 2020 00:57:14 +0000 (00:57 +0000)
committerStefan Baranoff <stefan.baranoff@trinitycyber.com>
Tue, 19 May 2020 01:03:23 +0000 (01:03 +0000)
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.

libarchive/archive_read_add_passphrase.c

index cf821b5d483c630e11893a03841433cae2707e54..f0b1ab93300f8f124aa5dd82ab0a24965c385b14 100644 (file)
@@ -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 *