From 1e85d81f5b4773275471fe7bbc707e8d64fb0a08 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 31 Jan 2024 21:00:44 -0500 Subject: trigger UB on unknown conversion specifier and invalid #/0 flags --- src/stdio/__printf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/stdio/__printf.c b/src/stdio/__printf.c index 72eb1585..db34e288 100644 --- a/src/stdio/__printf.c +++ b/src/stdio/__printf.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #ifdef _POSIX_SOURCE @@ -203,6 +204,12 @@ int (__printf)(struct io_options *opt, const char * format, va_list arg) flags |= UPPER; } + if ((flags & ALT) && (!strchr("xXaAeEfFgG", format[i]))) { + __undefined("In call to %s(): The # flag is undefined for %%%c", opt->fnname, format[i]); + } else if ((flags & ZERO) && (!strchr("diouxXaAeEfFgG", format[i]))) { + __undefined("In call to %s(): The 0 flag is undefined for %%%c", opt->fnname, format[i]); + } + switch (format[i]) { case 'o': /* unsigned int */ case 'u': @@ -324,7 +331,7 @@ int (__printf)(struct io_options *opt, const char * format, va_list arg) break; default: /* undefined */ - return -nout; + __undefined("In call to %s(): Unknown conversion specifier %%%c", opt->fnname, format[i]); } } -- cgit v1.2.1