From 1d1b64871eacf288229f973c2bbb003fb81d78fc Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Fri, 21 Apr 2023 22:33:32 +0100 Subject: Add C11 error checking to vsnprintf() C11 specifies that vsnprintf() is to check for the following conditions: - output buffer or format string are null pointers - buffer size is zero C11 also specifies "constraint handler functions" that may be set, but that's far more involved, and having at least some error-handling for bad arguments like these is probably quite useful. Source: https://en.cppreference.com/w/c/io/vfprintf#:~:text=5%2D8),constraint%20handler%20function%3A --- libpsn00b/libc/vsprintf.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libpsn00b/libc/vsprintf.c') diff --git a/libpsn00b/libc/vsprintf.c b/libpsn00b/libc/vsprintf.c index 9ca4cc5..585d23d 100644 --- a/libpsn00b/libc/vsprintf.c +++ b/libpsn00b/libc/vsprintf.c @@ -391,6 +391,9 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap) int zero_flag_imp = 0; int pad_quantity = 0; int last; + + // C11: required to check these cases and return error if detected + if (string == NULL || fmt == NULL || size == 0) { return -1; } l = strlen(fmt); -- cgit v1.2.3