From 168581307827c4f199b32698e43ded134b624c30 Mon Sep 17 00:00:00 2001 From: lephe Date: Tue, 16 Jul 2019 19:13:26 -0400 Subject: [PATCH] libc: fix a pointer overflow in kprint When the size of the input buffer is not specified, the default was INT_MAX; however this will cause the pointer value to overflow in many situations, causing kprint_flush() to flush prematurely and write NUL bytes at inappropriate places. This commit changes the default size to 65535. Morale: never use sprintf() or vsprintf()... --- src/std/stdio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/std/stdio.c b/src/std/stdio.c index 5ac7e76..d7a416b 100644 --- a/src/std/stdio.c +++ b/src/std/stdio.c @@ -15,7 +15,6 @@ #include #include -#include //--- // kprint() definitions @@ -565,7 +564,7 @@ GWEAK int sprintf(char *str, char const *format, ...) va_list args; va_start(args, format); - int count = kvsprint(str, INT_MAX, format, &args); + int count = kvsprint(str, 65536, format, &args); va_end(args); return count; @@ -574,7 +573,7 @@ GWEAK int sprintf(char *str, char const *format, ...) /* vsprintf() */ GWEAK int vsprintf(char *str, char const *format, va_list args) { - return kvsprint(str, INT_MAX, format, &args); + return kvsprint(str, 65536, format, &args); } /* snprintf() */