dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame 0001-agetty-keep-freed-issue-file-pointer-zeroized.patch

5972c3
From 9418ba6d05feed6061f5343741b1bc56e7bde663 Mon Sep 17 00:00:00 2001
5972c3
From: Karel Zak <kzak@redhat.com>
5972c3
Date: Fri, 20 Dec 2019 15:05:33 +0100
5972c3
Subject: [PATCH] agetty: keep freed issue file pointer zeroized
5972c3
5972c3
References: https://bugzilla.redhat.com/show_bug.cgi?id=1784536
5972c3
Signed-off-by: Karel Zak <kzak@redhat.com>
5972c3
---
5972c3
 term-utils/agetty.c | 15 +++++++++++----
5972c3
 1 file changed, 11 insertions(+), 4 deletions(-)
5972c3
5972c3
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
5972c3
index 3c20acc98..dfc4921f5 100644
5972c3
--- a/term-utils/agetty.c
5972c3
+++ b/term-utils/agetty.c
5972c3
@@ -1820,8 +1820,12 @@ static int issuefile_read_stream(
5972c3
 	if (fstat(fileno(f), &st) || !S_ISREG(st.st_mode))
5972c3
 		return 1;
5972c3
 
5972c3
-	if (!ie->output)
5972c3
-	       ie->output = open_memstream(&ie->mem, &ie->mem_sz);
5972c3
+	if (!ie->output) {
5972c3
+		free(ie->mem);
5972c3
+		ie->mem_sz = 0;
5972c3
+		ie->mem = NULL;
5972c3
+		ie->output = open_memstream(&ie->mem, &ie->mem_sz);
5972c3
+	}
5972c3
 
5972c3
 	while ((c = getc(f)) != EOF) {
5972c3
 		if (c == '\\')
5972c3
@@ -1965,8 +1969,10 @@ done:
5972c3
 	if (netlink_groups != 0)
5972c3
 		open_netlink();
5972c3
 #endif
5972c3
-	if (ie->output)
5972c3
+	if (ie->output) {
5972c3
 		fclose(ie->output);
5972c3
+		ie->output = NULL;
5972c3
+	}
5972c3
 }
5972c3
 
5972c3
 /* This is --show-issue backend, executed by normal user on the current
5972c3
@@ -1985,7 +1991,8 @@ static void show_issue(struct options *op)
5972c3
 
5972c3
 	if (ie.mem_sz)
5972c3
 		write_all(STDOUT_FILENO, ie.mem, ie.mem_sz);
5972c3
-
5972c3
+	if (ie.output)
5972c3
+		fclose(ie.output);
5972c3
 	free(ie.mem);
5972c3
 }
5972c3
 
5972c3
-- 
5972c3
2.21.0
5972c3