From 4f17393f3b2514945bf3fab0a7179ce6baf67a45 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Thu, 28 Feb 2019 20:30:28 -0500 Subject: set max length to a very big number, undefined behavior happens if the user provides too small a buffer --- src/stdio/sprintf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/stdio') diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c index 2872331a..bf5f5b6c 100644 --- a/src/stdio/sprintf.c +++ b/src/stdio/sprintf.c @@ -2,6 +2,13 @@ #include "stdarg.h" #include "nonstd/io.h" +#if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +#include "stdint.h" +#else +#include "limits.h" +#define SIZE_MAX INT_MAX +#endif + /** write formatted output to a string **/ int sprintf(char * restrict s, const char * restrict format, ...) { @@ -10,7 +17,7 @@ int sprintf(char * restrict s, const char * restrict format, ...) struct io_options opt = {0}; opt.fnname = "sprintf"; opt.string = s; - opt.maxlen = (size_t)-1; + opt.maxlen = SIZE_MAX; va_start(ap, format); ret = __printf(&opt, format, ap); va_end(ap); -- cgit v1.2.1