]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: keep freed issue file pointer zeroized
authorKarel Zak <kzak@redhat.com>
Fri, 20 Dec 2019 14:05:33 +0000 (15:05 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 20 Dec 2019 14:05:33 +0000 (15:05 +0100)
References: https://bugzilla.redhat.com/show_bug.cgi?id=1784536
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/agetty.c

index 3c20acc9813badb00ffa08ba5c1542de3297a3af..dfc4921f578231e078be5634ce0b34b2af005ea9 100644 (file)
@@ -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);
 }