From 32afa33a06d8def45c53ec57e5dba0eb12d8dc7c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 26 Aug 2025 15:26:06 +0300 Subject: [PATCH] LibC: Make sure FILE's buffer does not get overflown --- userspace/libraries/LibC/stdio.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/userspace/libraries/LibC/stdio.cpp b/userspace/libraries/LibC/stdio.cpp index cfac0835..cc36462b 100644 --- a/userspace/libraries/LibC/stdio.cpp +++ b/userspace/libraries/LibC/stdio.cpp @@ -779,11 +779,17 @@ int putc_unlocked(int c, FILE* file) return (unsigned char)c; } + if (file->buffer_idx >= file->buffer_size) + if (fflush(file) == EOF) + return EOF; + file->buffer[file->buffer_idx] = c; file->buffer_idx++; + if ((file->buffer_type == _IOLBF && c == '\n') || file->buffer_idx >= file->buffer_size) if (fflush(file) == EOF) return EOF; + return (unsigned char)c; }