From 9420484c9b41258e17c2f6cbd4f81f6ed4229f9b Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 3 Oct 2022 19:05:04 +0200 Subject: [PATCH] Do not use __builtin_alloca in puts (could overflow the stack for large strings) --- libs/libc/src/stdio.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libs/libc/src/stdio.cpp b/libs/libc/src/stdio.cpp index d7817778..48e08768 100644 --- a/libs/libc/src/stdio.cpp +++ b/libs/libc/src/stdio.cpp @@ -49,10 +49,8 @@ extern "C" } int puts(const char* s) { - size_t len = strlen(s); - char* output = (char*)__builtin_alloca(len + 1); - memcpy(output, s, len); - output[len] = '\n'; - return syscall(SYS_write, output, len + 1); + long nwritten = syscall(SYS_write, s, strlen(s)); + nwritten += syscall(SYS_write, "\n", 1); + return nwritten; } } \ No newline at end of file