summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-05-05 16:20:26 +0200
committerAnton Kling <anton@kling.gg>2024-05-05 16:20:26 +0200
commitc99d6608825c02783a58cddd930794cd0d35ab03 (patch)
treed9109d4d44b5bc0ac27f1c93201e5209ba9a7bf2 /userland
parent9d4ed1393d163514b317654cda736987b476f8a3 (diff)
LibC: fflush() should not dereference stream if it is NULL
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/stdio/fflush.c13
1 files changed, 10 insertions, 3 deletions
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 <stdio.h>
+#include <syscall.h>
+#include <errno.h>
// 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;
}