[Reproducible-commits] [dpkg] 10/25: libdpkg: Fix memory leaks in buffer_copy() on error conditions

Holger Levsen holger at layer-acht.org
Tue May 3 08:43:54 UTC 2016


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to annotated tag 1.16.16
in repository dpkg.

commit 0eb67a5a236d7fc7c03975e0fa28b783231f8f9f
Author: Guillem Jover <guillem at debian.org>
Date:   Wed Apr 30 22:32:15 2014 +0200

    libdpkg: Fix memory leaks in buffer_copy() on error conditions
    
    Cherry picked from commit ded3dfed77b7fd268914e19e8081b43c9233cc05 and
    commit b851df1817ebaf60a95ae6478824c0e732890fc0.
    
    Check for errors from subfunctions and break out of the loop to be able
    to release resources. Check also for unexpected EOF only after freeing
    resources, so that we don't end up leaking them.
    
    Warned-by: coverity
---
 debian/changelog  |  1 +
 lib/dpkg/buffer.c | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 265d7c9..085b498 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,6 +6,7 @@ dpkg (1.16.15+nmu1) UNRELEASED; urgency=low
     packages.
   * Do not leak color string on «dselect --color».
   * Fix memory leaks when parsing alternatives.
+  * Fix memory leaks in buffer_copy() on error conditions.
 
   [ Updated scripts translations ]
   * Fix typos in German (Helge Kreutzmann)
diff --git a/lib/dpkg/buffer.c b/lib/dpkg/buffer.c
index ec818f4..162b204 100644
--- a/lib/dpkg/buffer.c
+++ b/lib/dpkg/buffer.c
@@ -196,7 +196,7 @@ buffer_copy(struct buffer_data *read_data,
 	while (bufsize > 0) {
 		bytesread = buffer_read(read_data, buf, bufsize, err);
 		if (bytesread < 0)
-			return -1;
+			break;
 		if (bytesread == 0)
 			break;
 
@@ -212,20 +212,22 @@ buffer_copy(struct buffer_data *read_data,
 
 		byteswritten = buffer_write(write_data, buf, bytesread, err);
 		if (byteswritten < 0)
-			return -1;
+			break;
 		if (byteswritten == 0)
 			break;
 
 		totalwritten += byteswritten;
 	}
 
-	if (limit > 0)
-		return dpkg_put_error(err, _("unexpected end of file or stream"));
-
 	buffer_filter_done(filter);
 
 	free(buf);
 
+	if (bytesread < 0 || byteswritten < 0)
+		return -1;
+	if (limit > 0)
+		return dpkg_put_error(err, _("unexpected end of file or stream"));
+
 	return totalread;
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list