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

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