From e6ef806ef40a421435b1209f0f79d778c03fe04a Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 27 May 2024 13:04:16 -0400 Subject: handle use-after-close --- src/stdio/fclose.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/stdio/fclose.c') diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c index f438a9c2..37198fcb 100644 --- a/src/stdio/fclose.c +++ b/src/stdio/fclose.c @@ -26,7 +26,7 @@ int fclose(FILE *stream) SIGNAL_SAFE(0); flockfile(stream); - if (fflush(stream) == EOF) { + if (stream->operation == OP_OUTPUT && fflush(stream) == EOF) { /* set errno */ return EOF; } @@ -44,6 +44,7 @@ int fclose(FILE *stream) } memset(stream, '\0', sizeof(*stream)); + stream->fd = -1; /* RETURN_SUCCESS(0); -- cgit v1.2.1