Blame SOURCES/0028-libmount-use-fmemopen-in-more-robust-way-coverity-sc.patch

22a545
From d9fe56d8da9015694fcba5f3dd850becff677ab5 Mon Sep 17 00:00:00 2001
22a545
From: Karel Zak <kzak@redhat.com>
22a545
Date: Fri, 20 Sep 2019 13:00:19 +0200
22a545
Subject: [PATCH] libmount: use fmemopen() in more robust way [coverity scan]
22a545
22a545
Upstream: http://github.com/karelzak/util-linux/commit/026f7d302066a4e6f5a69dc9818ec3180939f4a3
22a545
Upstream: http://github.com/karelzak/util-linux/commit/bc747dfccf511419312ec872cefa90e25d83136a
22a545
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1751447
22a545
Signed-off-by: Karel Zak <kzak@redhat.com>
22a545
---
22a545
 libmount/src/utils.c | 18 ++++++++++++------
22a545
 1 file changed, 12 insertions(+), 6 deletions(-)
22a545
22a545
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
22a545
index f7d85d124..04e79f53f 100644
22a545
--- a/libmount/src/utils.c
22a545
+++ b/libmount/src/utils.c
22a545
@@ -1219,20 +1219,26 @@ success:
22a545
  */
22a545
 FILE *mnt_get_procfs_memstream(int fd, char **membuf)
22a545
 {
22a545
-	FILE *memf;
22a545
 	size_t sz = 0;
22a545
 	off_t cur;
22a545
 
22a545
+	*membuf = NULL;
22a545
+
22a545
 	/* in case of error, rewind to the original position */
22a545
 	cur = lseek(fd, 0, SEEK_CUR);
22a545
 
22a545
-	if (read_procfs_file(fd, membuf, &sz) == 0
22a545
-	    && sz > 0
22a545
-	    && (memf = fmemopen(*membuf, sz, "r")))
22a545
-		return memf;
22a545
+	if (read_procfs_file(fd, membuf, &sz) == 0 && sz > 0) {
22a545
+		FILE *memf = fmemopen(*membuf, sz, "r");
22a545
+		if (memf)
22a545
+			return memf;	/* success */
22a545
+
22a545
+		free(*membuf);
22a545
+		*membuf = NULL;
22a545
+	}
22a545
 
22a545
 	/* error */
22a545
-	lseek(fd, cur, SEEK_SET);
22a545
+	if (cur != (off_t) -1)
22a545
+		lseek(fd, cur, SEEK_SET);
22a545
 	return NULL;
22a545
 }
22a545
 #else
22a545
-- 
22a545
2.21.0
22a545