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()...
pull/1/head
lephe 3 years ago
parent ff2db385a8
commit 1685813078
  1. 5
      src/std/stdio.c

@ -15,7 +15,6 @@
#include <gint/defs/util.h>
#include <stdarg.h>
#include <limits.h>
//---
// 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() */

Loading…
Cancel
Save