From c99d6608825c02783a58cddd930794cd0d35ab03 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Sun, 5 May 2024 16:20:26 +0200 Subject: LibC: fflush() should not dereference stream if it is NULL --- userland/libc/stdio/fflush.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'userland') diff --git a/userland/libc/stdio/fflush.c b/userland/libc/stdio/fflush.c index 3042efa..1cadc72 100644 --- a/userland/libc/stdio/fflush.c +++ b/userland/libc/stdio/fflush.c @@ -1,8 +1,15 @@ #include +#include +#include // https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html int fflush(FILE *stream) { - if (stream->fflush) - stream->fflush(stream); - return 0; + if (stream) { + if (stream->fflush) { + stream->fflush(stream); + return 0; + } + } + errno = ENXIO; + return -1; } -- cgit v1.2.3