Blob Blame History Raw
From 9418ba6d05feed6061f5343741b1bc56e7bde663 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Fri, 20 Dec 2019 15:05:33 +0100
Subject: [PATCH] agetty: keep freed issue file pointer zeroized

References: https://bugzilla.redhat.com/show_bug.cgi?id=1784536
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 term-utils/agetty.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 3c20acc98..dfc4921f5 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -1820,8 +1820,12 @@ static int issuefile_read_stream(
 	if (fstat(fileno(f), &st) || !S_ISREG(st.st_mode))
 		return 1;
 
-	if (!ie->output)
-	       ie->output = open_memstream(&ie->mem, &ie->mem_sz);
+	if (!ie->output) {
+		free(ie->mem);
+		ie->mem_sz = 0;
+		ie->mem = NULL;
+		ie->output = open_memstream(&ie->mem, &ie->mem_sz);
+	}
 
 	while ((c = getc(f)) != EOF) {
 		if (c == '\\')
@@ -1965,8 +1969,10 @@ done:
 	if (netlink_groups != 0)
 		open_netlink();
 #endif
-	if (ie->output)
+	if (ie->output) {
 		fclose(ie->output);
+		ie->output = NULL;
+	}
 }
 
 /* This is --show-issue backend, executed by normal user on the current
@@ -1985,7 +1991,8 @@ static void show_issue(struct options *op)
 
 	if (ie.mem_sz)
 		write_all(STDOUT_FILENO, ie.mem, ie.mem_sz);
-
+	if (ie.output)
+		fclose(ie.output);
 	free(ie.mem);
 }
 
-- 
2.21.0