From 188161781d4f6b7c69cca3d4c2d7d96597393e0d Mon Sep 17 00:00:00 2001 From: rosenrost <52100845+rosenrost@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:15:51 +0100 Subject: [PATCH] Fix NULL pointer dereference in fflush(NULL) fflush(NULL) is defined to flush all output streams. The implementation unconditionally dereferenced the stream pointer and therefore crashed. As streams are unbuffered there is nothing to do in this case. --- sources/fflush.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sources/fflush.c b/sources/fflush.c index 263a984..5fdc1d6 100644 --- a/sources/fflush.c +++ b/sources/fflush.c @@ -2,7 +2,14 @@ int fflush(FILE *stream) { - stream->__pushback = EOF; - stream->__last_char = EOF; + /* + * streams are unbuffered, so there is nothing to write out. + * fflush(NULL) means "all streams" and must not dereference the pointer. + */ + if (stream != NULL) + { + stream->__pushback = EOF; + stream->__last_char = EOF; + } return 0; }