From: Karel Zak Date: Fri, 20 Dec 2019 14:05:33 +0000 (+0100) Subject: agetty: keep freed issue file pointer zeroized X-Git-Tag: v2.35-rc2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9418ba6d05feed6061f5343741b1bc56e7bde663;p=thirdparty%2Futil-linux.git agetty: keep freed issue file pointer zeroized References: https://bugzilla.redhat.com/show_bug.cgi?id=1784536 Signed-off-by: Karel Zak --- diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 3c20acc981..dfc4921f57 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); }