libbsd: Branch 'master' - 2 commits

Guillem Jover guillem at kemper.freedesktop.org
Sun Feb 7 09:18:35 CET 2016


 src/hash/helper.c |    4 +++-
 src/radixsort.c   |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

New commits:
commit cbe305770345161f4ce5069552db71fa350dcb0c
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Feb 7 02:53:28 2016 +0100

    Fix file descriptor leak in HASHFileChunk helper
    
    This leak only happens on error conditions, so it's not too bad.
    
    Warned-by: coverity

diff --git a/src/hash/helper.c b/src/hash/helper.c
index 06af189..1c63564 100644
--- a/src/hash/helper.c
+++ b/src/hash/helper.c
@@ -67,8 +67,10 @@ HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
 		}
 		len = sb.st_size;
 	}
-	if ((len < 0) || (off > 0 && lseek(fd, off, SEEK_SET) < 0))
+	if ((len < 0) || (off > 0 && lseek(fd, off, SEEK_SET) < 0)) {
+		close(fd);
 		return (NULL);
+	}
 
 	while ((nr = read(fd, buffer,
 	    (size_t)(len ? MIN(BUFSIZ, len) : BUFSIZ))) > 0) {
commit 5a32ea0a72ba9fa4275080a2a51612ae50f66dd3
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Feb 7 02:47:22 2016 +0100

    Fix unportable sizeof() usage
    
    We are calculating the size of the array, and need to pass the size of
    each element, not the size of a pointer to an element. Although this
    happens to be the same in many cases, this is not a portable assumption.
    
    Warned-by: coverity

diff --git a/src/radixsort.c b/src/radixsort.c
index 1473925..ad2ae70 100644
--- a/src/radixsort.c
+++ b/src/radixsort.c
@@ -118,7 +118,7 @@ sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
 	if (n < THRESHOLD)
 		simplesort(a, n, 0, tr, endch);
 	else {
-		ta = reallocarray(NULL, n, sizeof(a));
+		ta = reallocarray(NULL, n, sizeof(*a));
 		if (ta == NULL)
 			return (-1);
 		r_sort_b(a, ta, n, 0, tr, endch);


More information about the libbsd mailing list