Blame SOURCES/nfs-utils-2.3.3-lseek-error-handling.patch

9d9876
From fd2e952319c748e1c7babb1db97b371ebf6748a9 Mon Sep 17 00:00:00 2001
9d9876
From: Alice J Mitchell <ajmitchell@redhat.com>
9d9876
Date: Mon, 29 Jul 2019 15:47:40 +0100
9d9876
Subject: [PATCH] Fix the error handling if the lseek fails
9d9876
9d9876
The error case when lseek returns a negative value was not correctly handled,
9d9876
and the error cleanup routine was potentially leaking memory also.
9d9876
9d9876
Signed-off-by: Alice J Mitchell <ajmitchell@redhat.com>
9d9876
---
9d9876
 support/nfs/conffile.c | 8 +++++++-
9d9876
 1 file changed, 7 insertions(+), 1 deletion(-)
9d9876
9d9876
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
9d9876
index b6400be..6ba8a35 100644
9d9876
--- a/support/nfs/conffile.c
9d9876
+++ b/support/nfs/conffile.c
9d9876
@@ -500,7 +500,7 @@ conf_readfile(const char *path)
9d9876
 
9d9876
 	if ((stat (path, &sb) == 0) || (errno != ENOENT)) {
9d9876
 		char *new_conf_addr = NULL;
9d9876
-		size_t sz = sb.st_size;
9d9876
+		off_t sz;
9d9876
 		int fd = open (path, O_RDONLY, 0);
9d9876
 
9d9876
 		if (fd == -1) {
9d9876
@@ -517,6 +517,11 @@ conf_readfile(const char *path)
9d9876
 
9d9876
 		/* only after we have the lock, check the file size ready to read it */
9d9876
 		sz = lseek(fd, 0, SEEK_END);
9d9876
+		if (sz < 0) {
9d9876
+			xlog_warn("conf_readfile: unable to determine file size: %s",
9d9876
+				  strerror(errno));
9d9876
+			goto fail;
9d9876
+		}
9d9876
 		lseek(fd, 0, SEEK_SET);
9d9876
 
9d9876
 		new_conf_addr = malloc(sz+1);
9d9876
@@ -2162,6 +2167,7 @@ conf_write(const char *filename, const char *section, const char *arg,
9d9876
 	ret = 0;
9d9876
 
9d9876
 cleanup:
9d9876
+	flush_outqueue(&inqueue, NULL);
9d9876
 	flush_outqueue(&outqueue, NULL);
9d9876
 
9d9876
 	if (buff)
9d9876
-- 
9d9876
1.8.3.1
9d9876